Skip to content

Commit 0fa13ee

Browse files
authored
Fix race condition with garbage collection (#9465)
This change fixes an intermittent crash caused by a thread race condition. The crash happened when a CallbackHandler::Callback (triggered by engine.flush()) attempted to create an instance of a Structure of Arrays (SoA) like TransformManager, which adds items to SoA) at the same time that the garbage collection job (FEngine::gc, which removes items from SoA) was running. This conflict is resolved by modifying the logic to ensure that the garbage collection task completes synchronously before the callback operations begin.
1 parent 1d2b8a0 commit 0fa13ee

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

filament/src/details/Renderer.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,11 @@ void FRenderer::skipFrame(uint64_t vsyncSteadyClockTimeNano) {
292292
// do this before engine.flush()
293293
mResourceAllocator->gc(true);
294294

295-
// Run the component managers' GC in parallel
296-
// WARNING: while doing this we can't access any component manager
297-
auto& js = engine.getJobSystem();
298-
299-
auto *job = js.runAndRetain(jobs::createJob(js, nullptr, &FEngine::gc, &engine)); // gc all managers
300-
301295
engine.flush(); // flush command stream
302296

303-
// make sure we're done with the gcs
304-
js.waitAndRelease(job);
297+
// Run the component managers' GC
298+
auto& js = engine.getJobSystem();
299+
js.runAndWait(jobs::createJob(js, nullptr, &FEngine::gc, &engine)); // gc all managers
305300
}
306301

307302
bool FRenderer::shouldRenderFrame() const noexcept {
@@ -468,16 +463,11 @@ void FRenderer::endFrame() {
468463
// do this before engine.flush()
469464
mResourceAllocator->gc();
470465

471-
// Run the component managers' GC in parallel
472-
// WARNING: while doing this we can't access any component manager
473-
auto& js = engine.getJobSystem();
474-
475-
auto *job = js.runAndRetain(jobs::createJob(js, nullptr, &FEngine::gc, &engine)); // gc all managers
476-
477466
engine.flush(); // flush command stream
478467

479-
// make sure we're done with the gcs
480-
js.waitAndRelease(job);
468+
// Run the component managers' GC
469+
auto& js = engine.getJobSystem();
470+
js.runAndWait(jobs::createJob(js, nullptr, &FEngine::gc, &engine)); // gc all managers
481471
}
482472

483473
void FRenderer::readPixels(

0 commit comments

Comments
 (0)