briansemrau / godot_box2d

A C++ module that integrates the Box2D library with the Godot game engine by providing nodes for standard Box2D objects.
MIT License
45 stars 4 forks source link

Attempting to set a Box2DShapes 'size' during contact crashes the run executable. #70

Closed ShadyChibinko closed 3 years ago

ShadyChibinko commented 3 years ago

'size' being ambiguous depending on the shape type (i.e. Box2DRectShape=width/height, Box2DCircleShape=radius, etc.)

Godot Version: v3.2.2.stable

Branch: 3.x

Issue Description: If a Box2DFixture is in contact with another and you try to change the 'size' of its Box2DShape, the run executable will crash. It happens regardless of whether you increase, decrease, or reset the 'size' value to what it already is. Also occurs with fixtures in 'sensor' mode. I've tested this out with RectShape, CircleShape, and CapsuleShape. I can only assume Polygon and Segment behave the same.

Backtrace looks like this:

CrashHandlerException: Program crashed
[0] <couldn't map PC to fn name>
[1] <couldn't map PC to fn name>
. . .
[27] <couldn't map PC to fn name>
[28] <couldn't map PC to fn name>
[29] BaseThreadInitThunk
-- END OF BACKTRACE --

Steps to reproduce: Open the minimal reproduction project. Turn on 'Visible Collision Shapes' and run 'SetSizeTest.tscn'. Keys 1 & 2 shrink and expand the leftmost body, respectively. Keys 8 & 9 do the same for the rightmost body. Expand both bodies so they're colliding. Then try setting size again with any key.

Minimal reproduction project: Set.Size.In.Contact.Test.zip

Additional Information: Alternatively I've tried swapping out the shape resource entirely with a new one set to the desired size but it makes no difference.

briansemrau commented 3 years ago

This has been fixed very recently in #69. I'll merge that now. The changes in that PR solve an issue I found when deleting bodies and fixtures in contact. When you modify a fixture's shape, the b2Fixture is deleted and recreated as mandated by box2d, hence the crash.

Thank you for the bug report :)

briansemrau commented 3 years ago

Fixed in now-merged #69