VERSION
Phaser Box2D v1.1.0
PROBLEM
- The game crashes due to error when creating and destroying worlds for more than 32 times (which is valid use case for retrying levels and it's cleaner than cleaning up all bodies, forces, particles etc)
- This is due to the library pre-create an array of 32 worlds that is used when the
CreateWorld() is called.
- However, calling
b2DestroyWorld() does not allow the used worlds to be re-used. The subsequent CreateWorld() will simply use the next world in the array.
EXPECTED RESULT
The b2DestroyWorld() should allow the world to be reused, probably by resetting the world inUse flag back to false.
Or perhaps the function needs a Phaser-specific version that does the resetting, similar to CreateWorld() is the Phaser-specific version of b2CreateWorld().
STEPS TO REPRODUCE
- Create a Scene with the following
create() function:
async create() {
const worldDef = b2DefaultWorldDef();
const bodyDef = b2DefaultBodyDef();
bodyDef.type = DYNAMIC;
bodyDef.position = new b2Vec2(0, 0);
for (var i = 0; i < 35; i++) {
const worldId = CreateWorld(worldDef).worldId;
console.log("Created Box2D world with id:", worldId);
b2CreateBody(worldId, bodyDef);
b2DestroyWorld(worldId);
await new Promise(resolve => setTimeout(resolve, 500));
}
}
- Run the game on web platform
- Inspect the console log to see the error:

VERSION
Phaser Box2D v1.1.0
PROBLEM
CreateWorld()is called.b2DestroyWorld()does not allow the used worlds to be re-used. The subsequentCreateWorld()will simply use the next world in the array.EXPECTED RESULT
The
b2DestroyWorld()should allow the world to be reused, probably by resetting the worldinUseflag back tofalse.Or perhaps the function needs a Phaser-specific version that does the resetting, similar to
CreateWorld()is the Phaser-specific version ofb2CreateWorld().STEPS TO REPRODUCE
create()function: