Open JakMobius opened 3 years ago
Thanks for reporting this; it should be fixed now. I didn't use the pull request because I've had performance issues iterating Map/Set/etc. The fix acts more like the upstream box2d code.
So duplicate proxy pairs are OK? Isn't it a bottleneck? While debugging that, i've often seen that m_moveCount become very large sometimes, even on simple world setups. I'm actually thinking about making some benchmarks with and w/o Set.
The following code crashes at
b2_dynamic_tree:47
:The stack trace:
The issue seems to be in b2BroadPhase::BufferMove. When body get moved twice, its fixture proxies get duplicated in m_moveBuffer. When body is removed from the world, b2BroadPhase::UnBufferMove is called to remove those proxies from the m_moveBuffer. However, this method does not remove their duplicates. So, when UpdatePairs is called, they get processed as moved proxies even after their removal from the world, which causes null-check to fail.
This is not always the case. My game receives body move and destroy events from the server. It get crashed eventually, after several bullets were fired and removed from the world.
My suggested fix: Use ES6 Set for m_moveBuffer. Thus, no duplicates could be stored in this buffer. As far as I understand, b2BroadPhase::MoveProxy method may be called a lot of times for single proxy (Its documentation says that it can be called as many times as needed). So this approach will likely improve overall performance, preventing same proxy pairs from being processed multiple times. (Also, as
b2_broad_phase:121
line says, duplicate pairs are avoided, so this can lead to additional problems)