box2d icon indicating copy to clipboard operation
box2d copied to clipboard

Crash in b2UpdateBodyMassData because of missing increment of loop variable

Open simonvanbernem opened this issue 2 months ago • 1 comments

Hi,

while trying to update to the latest box2d commit, my game started crashing here, because the inertia was NaN: https://github.com/erincatto/box2d/blob/3a4f0da8374af61293a03021c9a0b3ebcfe67948/src/body.c#L626

This happens because this code doesn't increment shapeIndex before continuing, which causes the same shape mass data to be overwritten with 0 over and over, leaving garbage data in the remaining ones.

https://github.com/erincatto/box2d/blob/3a4f0da8374af61293a03021c9a0b3ebcfe67948/src/body.c#L589-L590

Adding shapeIndex += 1; fixes the crash

simonvanbernem avatar Nov 07 '25 15:11 simonvanbernem

Easy solve, stop using 0 density. :)

erincatto avatar Nov 10 '25 18:11 erincatto

Thanks for the report. Fixed in #1022

erincatto avatar Dec 15 '25 00:12 erincatto