stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

commit 58e27ae7696a8bd029d37497977b155ee3758d3e
parent 0979b6ace8754ec37f1b79c974dd81bb7c1c2b8b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 16 Nov 2022 11:53:11 +0100

Fix invalid memory access on image rendering

Render definition was not taken into account when writing the output
image, resulting in an invalid memory write when the image was not a
multiple of the tile size (used to distribute the rendering between
threads)

Diffstat:
Msrc/sdis_solve_camera.c | 10++++++++--
Msrc/test_sdis_solve_camera.c | 10+++++-----
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/sdis_solve_camera.c b/src/sdis_solve_camera.c @@ -268,15 +268,21 @@ write_tile { res_T res = RES_OK; size_t tile_org[2]; + size_t buf_sz[2]; + size_t tile_sz[2]; uint16_t x, y; ASSERT(buf && spp && tile); + SDIS(estimator_buffer_get_definition(buf, buf_sz)); + tile_org[0] = (size_t)(tile->data.x * TILE_SIZE); tile_org[1] = (size_t)(tile->data.y * TILE_SIZE); + tile_sz[0] = MMIN(TILE_SIZE, buf_sz[0] - tile_org[0]); + tile_sz[1] = MMIN(TILE_SIZE, buf_sz[1] - tile_org[1]); - FOR_EACH(y, 0, TILE_SIZE) { + FOR_EACH(y, 0, tile_sz[1]) { const size_t pix_y = tile_org[1] + y; - FOR_EACH(x, 0, TILE_SIZE) { + FOR_EACH(x, 0, tile_sz[0]) { const size_t pix_x = tile_org[0] + x; struct sdis_estimator* estimator = NULL; struct pixel* pixel = NULL; diff --git a/src/test_sdis_solve_camera.c b/src/test_sdis_solve_camera.c @@ -29,9 +29,9 @@ #include <string.h> #define UNKOWN_TEMPERATURE -1 -#define IMG_WIDTH 640 -#define IMG_HEIGHT 480 -#define SPP 4 /* #Samples per pixel, i.e. #realisations per pixel */ +#define IMG_WIDTH 157 +#define IMG_HEIGHT 53 +#define SPP 30 /* #Samples per pixel, i.e. #realisations per pixel */ /* * The scene is composed of a solid cube whose temperature is unknown. The @@ -741,7 +741,7 @@ main(int argc, char** argv) OK(sdis_solve_camera(scn, &solve_args, &buf2)); if(is_master_process) { OK(sdis_estimator_buffer_get_temperature(buf2, &T2)); - CHK(T.E != T2.E); + CHK(T.E != T2.E || (T2.SE == 0 && T.SE ==0)); CHK(T2.E + 3*T2.SE >= T.E - 3*T.SE && T2.E - 3*T2.SE <= T.E + 3*T.SE); OK(sdis_estimator_buffer_ref_put(buf2)); @@ -756,7 +756,7 @@ main(int argc, char** argv) OK(ssp_rng_ref_put(rng)); if(is_master_process) { OK(sdis_estimator_buffer_get_temperature(buf2, &T2)); - CHK(T.E != T2.E); + CHK(T.E != T2.E || (T2.SE == 0 && T.SE == 0)); CHK(T2.E + 3*T2.SE >= T.E - 3*T.SE && T2.E - 3*T2.SE <= T.E + 3*T.SE); OK(sdis_estimator_buffer_ref_put(buf2));