fix: physics segfault — keep layer filter objects alive as fields
BroadPhaseLayerInterfaceTable, ObjectLayerPairFilterTable, and ObjectVsBroadPhaseLayerFilterTable were local variables in the constructor. After GC collected them, Jolt crashed with dangling native pointers during PhysicsSystem.Update(). Now stored as readonly fields with proper Dispose in cleanup. Also fixed Flecs table lock assertion by collecting RigidBody init list before calling entity.Set().
This commit is contained in:
@@ -243,16 +243,21 @@ class Program
|
||||
// Physics: create bodies, step, sync transforms
|
||||
if (!cameraTour)
|
||||
{
|
||||
var toInit = new List<(Entity, RigidBody, Transform)>();
|
||||
world.Each((Entity e, ref RigidBody rb, ref Transform t) =>
|
||||
{
|
||||
if (!rb.IsInitialized)
|
||||
{
|
||||
physicsWorld.CreateBody(e, rb, t);
|
||||
rb.IsInitialized = true;
|
||||
e.Set(rb);
|
||||
}
|
||||
toInit.Add((e, rb, t));
|
||||
});
|
||||
|
||||
foreach (var (e, rbData, t) in toInit)
|
||||
{
|
||||
physicsWorld.CreateBody(e, rbData, t);
|
||||
var rb = rbData;
|
||||
rb.IsInitialized = true;
|
||||
e.Set(rb);
|
||||
}
|
||||
|
||||
physicsWorld.Update((float)timing.DeltaTime);
|
||||
physicsWorld.SyncTransforms(world);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user