Amerio.Stephane Posted January 23, 2023 Share Posted January 23, 2023 Hi, With the editor, add a Component storing a NodeReference into a property (eg named "noderef"). Assign it a node reference by drag n dropping an existing node. Now delete the source node reference. Obviously, the "noderef" property will now have an invalid node ref. The issue is this property can be saved with this incorrect value, and at runtime the "noderef" property will have some random pointer value in it, and we can't check if this value is invalid, which leads to a crash. I would suggest that at save time, you reset to null the invalid NodeReference properties in components. Thanks! Link to comment
mifril Posted January 24, 2023 Share Posted January 24, 2023 Hi, What version of SDK are you using? Can you send a code that reproduces this problem? How do you store NodeReferences? Am I trying to reproduce your problem correctly? This code shows "NO" when NodeRefence invalid. class TestNodeRefComponent : public Unigine::ComponentBase { public: COMPONENT_DEFINE(TestNodeRefComponent, Unigine::ComponentBase); COMPONENT_INIT(init); COMPONENT_UPDATE(update); PROP_PARAM(Node, nodeRefence); private: void init() { node = nodeRefence.get(); } void update() { if (node) Unigine::Log::message("OK\n"); else Unigine::Log::message("NO\n"); } Unigine::NodePtr node; }; Link to comment
Amerio.Stephane Posted January 24, 2023 Author Share Posted January 24, 2023 After a deeper debug, the issue is not in the Property content itself, but in the way the PropertyNodePtr is auto converted to a NodePtr. In my case, the "if (node)" never catches the null ptr, it always passes. I actually have to write "if (node.get())" to check the null ptr. Not sure why, but it is confirmed. As a side note, the Param Node is inside a param struct inside a param array, it it matters. Link to comment
mifril Posted January 25, 2023 Share Posted January 25, 2023 If the problem is with a variable named "node", then perhaps it arises due to the fact that the node is a member of the ComponentBase, which is why the node.get() actually had to be used. In my example, I missed this point, but in visual studio everything compiled fine for me. But still it is worth considering this when naming variables. Link to comment
Amerio.Stephane Posted January 25, 2023 Author Share Posted January 25, 2023 Yes, in my case it was PROP_PARAM(Node, node); So the issue is a PROP_PARAM_NODE can be be auto converted to a bool, but it is not the same as calling get() on the variable, which is confusing and error prone. Link to comment
silent Posted January 26, 2023 Share Posted January 26, 2023 Yes, that very C++ moment :) We will see if we can do something here to improve this behavior. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts