Skip to content

Internal assert is hit, which looks like an integer overflow bug #1028

@simonvanbernem

Description

@simonvanbernem

Hi,

I have been playtesting my game a little, and have observed crashes, which originate from an assert in solver.c:

B2_ASSERT( startIndex <= endIndex );

It crashes with this callstack:

spaced.exe!b2IntegratePositionsTask(int startIndex, int endIndex, b2StepContext * context) Line 221 (c:\Workspaces\spaced\source\modules\box2d\src\solver.c:221)
spaced.exe!b2ExecuteBlock(b2SolverStage * stage, b2StepContext * context, b2SolverBlock * block, int workerIndex) Line 901 (c:\Workspaces\spaced\source\modules\box2d\src\solver.c:901)
spaced.exe!b2ExecuteStage(b2SolverStage * stage, b2StepContext * context, int previousSyncIndex, int syncIndex, int workerIndex) Line 965 (c:\Workspaces\spaced\source\modules\box2d\src\solver.c:965)
spaced.exe!b2ExecuteMainStage(b2SolverStage * stage, b2StepContext * context, unsigned int syncBits) Line 1025 (c:\Workspaces\spaced\source\modules\box2d\src\solver.c:1025)
spaced.exe!b2SolverTask(int startIndex, int endIndex, unsigned int threadIndexIgnore, void * taskContext) Line 1156 (c:\Workspaces\spaced\source\modules\box2d\src\solver.c:1156)
spaced.exe!b2DefaultAddTaskFcn(void(*)(int, int, unsigned int, void *) task, int count, int minRange, void * taskContext, void * userContext) Line 80 (c:\Workspaces\spaced\source\modules\box2d\src\physics_world.c:80)
spaced.exe!b2Solve(b2World * world, b2StepContext * stepContext) Line 1806 (c:\Workspaces\spaced\source\modules\box2d\src\solver.c:1806)
spaced.exe!b2World_Step(b2WorldId worldId, float timeStep, int subStepCount) Line 799
...

In the crash, endIndex has the value -32768, which looks like a wrapped int16. At solver.c:965 in b2ExecuteStage, blocks contains a single block with startIndex = 0 and count = -32768.

When the crash happens, the game has created and destroyed many thousands of bodies and shapes (they are particles simulating the exhaust of a rocket engine), so it seems plausible that some int16 counter got incremented per shape/body created/destroyed and wrapped around this way.

Additionally, I had a bug where I didn't destroy the particle bodies properly. At the time of the crash, there are 6100 shapes but 131079 bodies (most of them dynamic bodies with no shape).

Let me know if this is enough information for a fix, or if I should dig deeper. I have only reproduced the bug with a release build, which makes stuff somewhat awkward to debug, but if necessary, I could probably get it with a debug build and provide a minidump and so on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions