Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,25 @@ class ThermionViewerFFI extends ThermionViewer {
}
View_setScene(view.getNativeHandle(), nullptr);

// Detach from any swap chain in the RenderManager BEFORE destroying
// the view. RenderManager's `_attachments` map (Dart side) keys
// each swap-chain entry to a list of (renderOrder, View) tuples;
// if `destroyView` runs while this view is still listed, the next
// `attach`/`detach`/`_syncViews` call from any other viewer will
// pass the dangling native pointer to
// `RenderManager_setRenderableRenderThread`, where Filament does
// a `handle_cast` and aborts with
// "Postcondition: corrupted heap Handle ... tag=(no tag)" — the
// generic symptom of dereferencing a freed handle.
//
// Reproduces in multi-viewer Flutter apps when one viewer is
// disposed while another is concurrently attaching its view: the
// disposing viewer's `View_destroy` runs before the surviving
// viewer's `_syncViews`, the survivor walks `_attachments`,
// pushes the freed pointer to RenderManager, and crashes.
// Detach-before-destroy keeps `_attachments` consistent.
await FilamentApp.instance!.renderManager.detach(view);

await FilamentApp.instance!.destroyScene(scene);
await FilamentApp.instance!.destroyView(view);

Expand Down
Loading