Implement the following plan: Plan: Fix Crash on Blender Level Load Context After…
- User
Implement the following plan:
Plan: Fix Crash on Blender Level Load
Context
After implementing the
-colliderchild import feature, the game crashes when loading the Blender level. Two errors appear:LevelLoadRequestSystemtries to load"Blender_Level"as an LDtk file and fails (pre-existing, caught)SpritePrepSystem.CreateNinePatchTexturecrashes with "Texture height must be greater than zero"
Root Cause Analysis
The crash chain:
ColliderDebugSystemis instantiated atLoadLevelExampleGameScreen.cs:284even though thedebugSystemsvariable is commented out of the pipeline at line 296- Its constructor (
ColliderDebugSystem.cs:33-34) subscribes toSubscribeEntityComponentAdded<BoxCollider>andSubscribeEntityComponentAdded<ConvexCollider>— these subscriptions are always active - When
BlenderLevelParserSystem.ApplyColliderChildsets aConvexCollideron a parent entity, the subscription fires andAddDebugLinesToConvexEntitycreates a debug entity withNinePatchDataandSize = aabb.Size - The
elephant-kid-colliderhas degenerate vertices — all 32 vertices haveY = 0.0(the mesh is on the XY plane in Blender instead of the XZ plane). This means AABB height = 0 CullingSystemaddsVisibleto the debug entity (it's in camera bounds)SpritePrepSystemtries to create aRenderTarget2Dwith height 0 → crash
The degenerate vertices issue: The
elephant-kid-collidermesh in Blender lies flat on the XY plane. Our exporter maps(X, -Z)to game coords, so Z=0 for all vertices → all game Y = 0. The mesh needs to be on the XZ plane for proper 2D projection (this is a Blender authoring issue, but the code should handle it gracefully).Fixes
1. Guard ColliderDebugSystem subscription
File:
MonoDreams.Examples/Screens/LoadLevelExampleGameScreen.csThe
ColliderDebugSystemis constructed but never used. Since its constructor subscribes to world events, it creates ghost debug entities. Wrap the construction in a conditional or move it behind the same comment gate asdebugSystemsusage: Assistant
I'll start by reading all three files that need modification in parallel.
Assistant
Now I have full context on all three files. Let me implement the three fixes.
Assistant
All three fixes are in. Let me build to verify everything compiles.
Assistant
Output was truncated. Let me check specifically for build errors.
Assistant
The
maxYvariable I introduced in the guard conflicts with the existingmaxYat line 612. Let me read the current state of the method and fix it.Assistant
The second
maxYloop at line 611-616 is now redundant since we already computed it. I'll remove it and reuse the existing value.Assistant
Build succeeded with 0 errors. Now let me run the tests.
Assistant
All 26 tests pass. Here's a summary of the changes:
Fix 1:
LoadLevelExampleGameScreen.cs:283-285Commented out the
ColliderDebugSystemconstruction. Previously only its usage in the pipeline was commented out, but the constructor still ran and subscribed to world events — creating ghost debug entities for every collider.Fix 2:
BlenderLevelParserSystem.cs:564-578Added a degenerate-vertex guard in
ApplyColliderChild. After buildingmodelVertices, it now computes the AABB and checks that both width and height are >= 0.01. Degenerate shapes (like theelephant-kid-colliderwith all Y=0) get a warning log and are skipped. This also eliminated the redundantmaxYloop that followed.Fix 3:
ColliderDebugSystem.cs:40-41, 64-65Added defense-in-depth guards in both
AddDebugLinesToEntityandAddDebugLinesToConvexEntity— early-returning if the AABB size has a zero dimension, preventing theRenderTarget2Dcreation crash even if a degenerate collider slips through.- User
Assistant
Let me read the existing plan file and then explore the relevant code to understand the vertex export pipeline.
Assistant
Good findings. The exploration confirms the root cause clearly. Let me ask which fix approach you prefer before writing the plan.
Assistant
Let me read the exporter script carefully to understand the current vertex transformation logic.
Assistant
Let me check the actual elephant-kid-collider data in the JSON to confirm the vertex values and understand the object's transform.
Assistant
Now I have the full picture. The elephant-kid-collider has
rotation: -0.0(no rotation), mesh on XY plane, anddimensions.y: 8.2638shows the Y extent exists but gets lost in the(X, -Z)projection. Let me also quickly check a working collider to compare.Assistant
Good. I now have all the information I need. Let me write the plan.
- User
[Request interrupted by user for tool use]