Jump to content

Component can be saved with invalid Node reference, not catchable at runtime (crash)


photo

Recommended Posts

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

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

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

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

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
×
×
  • Create New...