Jump to content

[SOLVED] getParameterPtr is not nullptr when access id that not exist


photo

Recommended Posts

from docs:

Quote

 

Ptr<PropertyParameter> getParameterPtr( int id )

Returns a property parameter by its ID.

Arguments

  • int id - Property parameter ID.

Return value

Property parameter smart pointer, if it exists; otherwise, nullptr.

 

 

As getNumParameters function deprecated, and i want to iterate through all parameters of my property, i go as:

for (int i = 0; property->getParameterPtr(i); i++) {

when i reaches 15 if logs into console:

 Property::getParameterPtr(): can't get parameter with id 15 in property "xxx_xxx"

and it is not nullptr, as it said in docs.

How can i handle that?

 

UPD: found way to get count of parameters through getNumChildren() at root parameter, but question about nullptr still actual.

Edited by qwert_e
Link to comment

Hi qwert_e,

Yes, there is a mistake. getParameterPtr() never returns nullptr. It always returns a PropertyParameter object, but the isExist() method may return 0.
And, you can't iterate through all of your parameters by one loop. Only through recursive function:

PropertyParameterPtr root_parameter = property->getParameterPtr();
std::function<void(const PropertyParameterPtr &)> recursive_func = [&, this](const PropertyParameterPtr &p)
{
	for (int i = 0; i < p->getNumChildren(); i++)
	{
		PropertyParameterPtr child = p->getChild(i);
		
		// do something...
		
		recursive_func(child);
	}
};
recursive_func(root_parameter);


Best regards,
Alexander

  • Like 2
Link to comment
  • silent changed the title to [SOLVED] getParameterPtr is not nullptr when access id that not exist
×
×
  • Create New...