magnopus-opensource / connected-spaces-platform

"An interoperable communication library for the spatial internet."
https://www.magnopus.com/csp
Apache License 2.0
89 stars 12 forks source link

Generated `SpaceEntity.GetParentEntity()` returns wrapped null pointer, causing hard crash #524

Closed magnopus-swifty closed 2 weeks ago

magnopus-swifty commented 3 weeks ago

Describe the bug

In the generated C# code, SpaceEntity.GetParentEntity() looks like this:

public Csp.Multiplayer.SpaceEntity GetParentEntity()
{
    var _result = new Csp.Multiplayer.SpaceEntity(
        csp_multiplayer_SpaceEntity_GetParentEntityC_SpaceEntityP(_ptr)
    );

    return _result;
}

In the C++ code (SpaceEntity.h) GetParentEntity() returns nullptr when the entity has no parent.

The generated code should do a null check when wrapping a NativePointer and return a null managed object.

To Reproduce

In C#, call SpaceEntity.GetParentEntity() in a space on any entity that doesn't have a parent.

Expected behaviour

SpaceEntity.GetParentEntity() should return null.

CSP version (please complete the following information):

v5.3.1+544

Language:

C#

magnopus-swifty commented 3 weeks ago

this line of Method.mustache needs modifying to check the return value of the called function before wrapping it.