Hi!
I have a mysterious crash that I'm unable to track down the reason for. This is the relevant part of the callstack:
System.Private.CoreLib.dll!System.Diagnostics.DebugProvider.Fail(string message, string detailMessage) Line 32
BepuUtilities.dll!BepuUtilities.Memory.Buffer<BepuPhysics.Collidables.Collidable>.this[int].get(int index) Line 56
BepuPhysics.dll!BepuPhysics.Statics.RemoveAt(int index) Line 184
BepuPhysics.dll!BepuPhysics.Statics.Remove(int handle) Line 224
(The assert triggers because HandleToIndex[handle] is -1)
I've verified that the handle has been added properly and is not removed twice. I'm removing a whole bunch of statics in a loop and it fails after deleting a handful of them; it's deterministic and reproable.
Understanding the statics tree and handle/index thing is tricky; but looking at Statics.RemoveAt it seems it's deleting the next-to-last leaf, causing the last leaf to move up into its place.. but leaving HandleToIndex for the handle pointing at the old location; now outside the tree.
If I misunderstand the code and it's all fine; what could cause this crash and how can I figure out what's happening?
Thanks again for your great support of this library!
--michael
removing lots of statics crash
Re: removing lots of statics crash
HandleToIndex[handle] == -1 is indeed an implication that the was never added or was already removed, as you mentioned. Nothing else should cause that error under normal conditions. It can also happen due to asynchronous corruption- either multiple threads working on adds/removes simultaneously or adding/removing to the simulation while it's running.
I'm attempting to reproduce in the demos and can't so far. FountainStressTestDemo (which covers constant randomized add/removes) passes for as long as I care to run it too.
I'll probably need a repro in the demos to look at to figure it out.
I'm attempting to reproduce in the demos and can't so far. FountainStressTestDemo (which covers constant randomized add/removes) passes for as long as I care to run it too.
I'll probably need a repro in the demos to look at to figure it out.
Re: removing lots of statics crash
Some more debugging reveals the problem to be that Statics.broadPhase.leaves[42] and Statics.broadPhase.leaves[53] both point to handle 49. When the first broadphase index is removed; HandleToIndex[49] gets set to -1; causing the removal of broadphase index 53 to blow up.
The reason it exists twice is that it gets added once simulation.Statics.Add and then again when I apply a description via simulation.Statics.ApplyDescription.
Is multiple entries in the broadphase tree valid or invalid? If invalid; then perhaps a check in ApplyDescriptionByIndex is required? Or I might have misunderstood... there's a lot of lists, indices and handles that are hard to reason about with my limited knowledge![Smile :-)](./images/smilies/icon_smile.gif)
(or are there restrictions around ApplyDescription I need to adher to?)
The reason it exists twice is that it gets added once simulation.Statics.Add and then again when I apply a description via simulation.Statics.ApplyDescription.
Is multiple entries in the broadphase tree valid or invalid? If invalid; then perhaps a check in ApplyDescriptionByIndex is required? Or I might have misunderstood... there's a lot of lists, indices and handles that are hard to reason about with my limited knowledge
![Smile :-)](./images/smilies/icon_smile.gif)
(or are there restrictions around ApplyDescription I need to adher to?)
Re: removing lots of statics crash
There we go, reproduced- static ApplyDescription is busted. Working on it now.
Re: removing lots of statics crash
Should be fixed in https://github.com/bepu/bepuphysics2/co ... 4f4f1aad63. Still needs a bit more testing (and there's an inconsistency in behavior with bodies that needs to be addressed), but the core crash should be gone.
Re: removing lots of statics crash
This patch solves my issues completely. Awesome support again; thanks!