Engine Crash - ComputeCentroid (Solved)

After some refactoring, I am unable to spawn a certain game object from a factory:

local id = factory.create(msg.url(nil, h_str.go_factory, "factory_bullet"), origin)

The arguments are all valid. The bullet game object looks like this:

Screenshot 2023-01-31 133223

The crash report looks like this:

Assertion failed: area > 1.192092896e-07F, file ..\src\box2d\Box2D\Collision\Shapes\b2PolygonShape.cpp, line 123

ERROR:CRASH: CALL STACK:

ERROR:CRASH:  0 0x7FF76AD8EB00 dmCrash::GenerateCallstack D:\a\defold\defold\engine\crash\src\backtrace_win32.cpp:144

ERROR:CRASH:  1 0x7FF76B04F800 raise /tmp/job3346579891437359884/minkernel/crts/ucrt/src/appcrt/misc/signal.cpp:547

ERROR:CRASH:  2 0x7FF76B0437F4 abort /tmp/job3346579891437359884/minkernel/crts/ucrt/src/appcrt/startup/abort.cpp:71

ERROR:CRASH:  3 0x7FF76B042A40 common_assert_to_stderr<wchar_t> /tmp/job3346579891437359884/minkernel/crts/ucrt/src/appcrt/startup/assert.cpp:186

ERROR:CRASH:  4 0x7FF76B042564 _wassert /tmp/job3346579891437359884/minkernel/crts/ucrt/src/appcrt/startup/assert.cpp:443

ERROR:CRASH:  5 0x7FF76AF27150 ComputeCentroid D:\a\defold\defold\engine\physics\src\box2d\Box2D\Collision\Shapes\b2PolygonShape.cpp:123

ERROR:CRASH:  6 0x7FF76AF25B60 b2PolygonShape::Set D:\a\defold\defold\engine\physics\src\box2d\Box2D\Collision\Shapes\b2PolygonShape.cpp:180

ERROR:CRASH:  7 0x7FF76AEBF920 dmPhysics::TransformCopyShape D:\a\defold\defold\engine\physics\src\physics\physics_2d.cpp:819

ERROR:CRASH:  8 0x7FF76AEBB290 dmPhysics::NewCollisionObject2D D:\a\defold\defold\engine\physics\src\physics\physics_2d.cpp:967

ERROR:CRASH:  9 0x7FF76AE995D0 dmGameSystem::CreateCollisionObject D:\a\defold\defold\engine\gamesys\src\gamesys\components\comp_collision_object.cpp:410

ERROR:CRASH: 10 0x7FF76AE973C0 dmGameSystem::CompCollisionObjectCreate D:\a\defold\defold\engine\gamesys\src\gamesys\components\comp_collision_object.cpp:459

ERROR:CRASH: 11 0x7FF76ADCDDC0 dmGameObject::CreateComponents D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:829

ERROR:CRASH: 12 0x7FF76ADD2000 dmGameObject::SpawnInternal D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:1172

ERROR:CRASH: 13 0x7FF76ADCAA70 dmGameObject::Spawn D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:1628

ERROR:CRASH: 14 0x7FF76AF3E390 dmGameSystem::FactoryComp_Create D:\a\defold\defold\engine\gamesys\src\gamesys\scripts\script_factory.cpp:344

ERROR:CRASH: 15 0x7FF76AD45E0E lj_BC_FUNCC <unknown>:0

ERROR:CRASH: 16 0x7FF76AD86080 lua_pcall <unknown>:0

ERROR:CRASH: 17 0x7FF76ADBA590 dmScript::PCallInternal D:\a\defold\defold\engine\script\src\script.cpp:1386

ERROR:CRASH: 18 0x7FF76ADB72C0 dmScript::InvokeCallback D:\a\defold\defold\engine\script\src\script.cpp:1778

ERROR:CRASH: 19 0x7FF76AE6E650 dmScript::LuaTimerCallback D:\a\defold\defold\engine\script\src\script_timer.cpp:517

ERROR:CRASH: 20 0x7FF76AE6D1A0 dmScript::UpdateTimers D:\a\defold\defold\engine\script\src\script_timer.cpp:228

ERROR:CRASH: 21 0x7FF76AE6D140 dmScript::TimerUpdateScriptWorld D:\a\defold\defold\engine\script\src\script_timer.cpp:460

ERROR:CRASH: 22 0x7FF76ADB61D0 dmScript::UpdateScriptWorld D:\a\defold\defold\engine\script\src\script.cpp:1125

ERROR:CRASH: 23 0x7FF76ADF6CB0 dmGameObject::CompScriptUpdate D:\a\defold\defold\engine\gameobject\src\gameobject\comp_script.cpp:254

ERROR:CRASH: 24 0x7FF76ADD5460 dmGameObject::Update D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:2572

ERROR:CRASH: 25 0x7FF76AE963A0 dmGameSystem::CompCollectionProxyUpdate D:\a\defold\defold\engine\gamesys\src\gamesys\components\comp_collection_proxy.cpp:299

ERROR:CRASH: 26 0x7FF76ADD5460 dmGameObject::Update D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:2572

ERROR:CRASH: 27 0x7FF76AE41E70 dmEngine::StepFrame D:\a\defold\defold\engine\engine\src\engine.cpp:1570

ERROR:CRASH: 28 0x7FF76AE3D0A0 dmEngineUpdate D:\a\defold\defold\engine\engine\src\engine.cpp:2098

ERROR:CRASH: 29 0x7FF76AE42890 dmEngine::RunLoop D:\a\defold\defold\engine\engine\src\engine_loop.cpp:83

ERROR:CRASH: 30 0x7FF76AD7C3B0 engine_main D:\a\defold\defold\engine\engine\src\engine_main.cpp:148

ERROR:CRASH: 31 0x7FF76B007194 __scrt_common_main_seh d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288

ERROR:CRASH: 32 0x7FFF50EB5590 BaseThreadInitThunk <unknown>:0

ERROR:CRASH: 33 0x7FFF51B84830 RtlUserThreadStart <unknown>:0

Trace 5 looks like the culprit. It fails an assert in ComputerCentroid. I guess this is saying the computed area of the collision shape is less than some minimum value, however the two collision objects attached to that game object are [ w = 8, h = 8, d = 1 ] and [ w = 24, h = 24, d = 1 ]. If I delete just one of these collisionobjects, the crash still occurs. If I delete both of these collisionobjects, the crash does not occur. I tried deleting those collisionobject files and remaking them, deleting the game object file and remaking it, and changing the shape dimensions, however none of those fixed it.

Edit: I also tried moving the factory components to another url which did not help. Interestingly, I tried spawning any other game object from factories, but apparently they are all failing.

Try to change physics scale. Looks like default scale is too small.

More info about box2d units.
https://box2d.org/documentation/index.html#autotoc_md17

Scale 1.0 has worked until now, so I don’t think that is the issue. (But to check I made it very big and very small but no change.)

1 Like

Hmm scale 1 is ok for bodies with size 8,1,24.
I think default value was smaller:)

1 Like

Hm. The scale of the game object containing (or spawning? I’m not sure) the factory is used by default. Is it super small like 0.00001? I bet on this, let’s double-check it.

1 Like

Maybe something with shape or object rotation?

Ah, yes I must have accidentally set the parent game object’s scale to 0.000001 when I was moving things around in the collection. Sometimes the editor starts out in scale mode instead of translate mode.

Thanks everyone. Solved.

6 Likes