Skip to content

Commit f6b88b9

Browse files
authored
fix: Fix testrender GPU regression with bad destruction order (#1814)
A few months back, PR #1733 seems to have switched the order that testrender destroys the shading system versus the renderer (services). This made some subtle bugs that were only symptomatic for GPU renders, but it's because of the destructor order, where the shadingsystem's dtr still references the renderer, which cannot be destroyed yet. The clue is that the SS's constructor takes the RS pointer as an argument. The RS, then, must have been constructed before the SS, and therefore we should expect it to be a requirement for the RS to outlast the lifetime of the SS. (Complex objects should be destroyed in the opposite order that they were constructed, if they contain references to each other.) One code change is needed to avoid the sanitizer errors that the incorrect change was originally meant to address: clear shaders when SimpleRayTracer clears. Signed-off-by: Larry Gritz <lg@larrygritz.com> --------- Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent bba9b35 commit f6b88b9

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/testrender/optixraytracer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ OptixRaytracer::finalize_pixel_buffer()
12531253
void
12541254
OptixRaytracer::clear()
12551255
{
1256-
shaders().clear();
1256+
SimpleRaytracer::clear();
12571257
OPTIX_CHECK(optixDeviceContextDestroy(m_optix_ctx));
12581258
m_optix_ctx = 0;
12591259
}

src/testrender/simpleraytracer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,4 +1101,10 @@ SimpleRaytracer::render(int xres, int yres)
11011101

11021102

11031103

1104+
void
1105+
SimpleRaytracer::clear()
1106+
{
1107+
shaders().clear();
1108+
}
1109+
11041110
OSL_NAMESPACE_EXIT

src/testrender/simpleraytracer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class SimpleRaytracer : public RendererServices {
8282
virtual void prepare_render();
8383
virtual void warmup() {}
8484
virtual void render(int xres, int yres);
85-
virtual void clear() {}
85+
virtual void clear();
8686

8787
// After render, get the pixels into pixelbuf, if they aren't already.
8888
virtual void finalize_pixel_buffer() {}

src/testrender/testrender.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ main(int argc, const char* argv[])
368368

369369
// We're done with the shading system now, destroy it
370370
rend->clear();
371-
delete rend;
372371
delete shadingsys;
372+
delete rend;
373373
return EXIT_SUCCESS;
374374
}

0 commit comments

Comments
 (0)