Skip to content

Suggestion: Liberally sprinkle assertf into Engine code #138

@thekovic

Description

@thekovic

It's happened to me multiple times now that I made a mistake where something is not configured correctly in the project. This usually manifests as a nullptr somewhere deep in the C++ Engine code and this results in a crash screen saying something like:

******* CPU EXCEPTION *******
NULL pointer dereference (read) exception at PC:8002A07C
Exception address: 00000000
GPR:
zr: ---- ---- 0000 0000   at: ---- ---- 0000 0000   v0: ---- ---- 0000 0000   v1: ---- ---- 8012 1ac0
a0: ---- ---- 0000 0000   a1: ---- ---- 0000 0000   a2: ---- ---- 0000 0004   a3: ---- ---- 0000 0030
t0: ---- ---- 0000 004d   t1: ---- ---- 0000 0001   t2: ---- ---- 0000 0000   t3: ---- ---- 0000 0000
t4: ---- ---- 8004 0c90   t5: ---- ---- 0000 0006   t6: ---- ---- 0000 0000   t7: ---- ---- 0000 00f0
s0: ---- ---- 8012 1a68   s1: ---- ---- 8012 17d4   s2: ---- ---- 8012 1a10   s3: ---- ---- 800a e858
s4: ---- ---- 807f fe60   s5: ---- ---- 8012 17d0   s6: ---- ---- 0000 0002   s7: ---- ---- 8012 1a44
t8: ---- ---- 0000 0008   t9: ---- ---- 0000 006d   k0: ---- ---- 0000 0014   k1: ---- ---- 0000 0000
gp: ---- ---- 8008 65f0   sp: ---- ---- 807f fd40   s8: ---- ---- 8012 17d4   ra: ---- ---- 8002 f0ec
lo: ---- ---- 0000 0008   hi: ---- ---- 0801 21ef   

Backtrace:
    P64::Coll::Mesh::load(void*)+0x0 (src/collision/meshLoader.cpp:52) [0x8002a07c]
    P64::Comp::CollMesh::initDelete(P64::Object&, P64::Comp::CollMesh*, u16*)+0xb4 (src/scene/components/collMesh.cpp:60) [0x8002f0e4]
    P64::Scene::loadObject(u8*&, std::function<void (P64::Object&)>)+0x2a4 (src/scene/sceneLoader.cpp:143) [0x80028bc0]
    P64::Scene::loadScene()+0xd4 (src/scene/sceneLoader.cpp:176) [0x80028ce4]
    P64::Scene::Scene(u16, P64::Scene**)+0x2b0 (src/scene/scene.cpp:90) [0x80028700]
    P64::SceneManager::run()+0x30 (src/scene/sceneManager.cpp:35) [0x80028d88]
    main+0x2e8 (src/main.cpp:110) [0x80025e40]
    _start+0x6c (??:0) [0x8000046c]

At first glance, this is incredibly scary-looking and not particularly helpful. I was able to figure out eventually what was wrong in this particular case (I didn't check the "Collision" box on an asset I used as collision mesh. However, it would be nice if the Engine code, like libdragon itself, could be liberally sprinkled with assertfs that check if inputs are not null or check other assumptions made by the code so that when something goes wrong, the user has a chance to see a more friendly error message.

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