How is the REALGetClassProperty / REALCountClassProperties used

Hello

I have for first time been trying REALGetClassProperty / REALCountClassProperties in attempt to speed things up a bit.

But I think I am using it wrong somehow, since I get crash. (Guessing it has something to do with the param, which I was not understanding the use of maybe)

So my question is how is it supposed to be used ?

(see my crash example bellow)

RBInteger count = REALCountClassProperties(shapeInstance);

OutputDebugStringA("Counted.....");

void* getter;
void* setter;
long param = 0;
REALstring declaration;
size_t numBytes;

for (RBInteger i = 0; i < count; ++i)
{
	OutputDebugStringA("Step in the for loop.....");  // We get this

	if (REALGetClassProperty(shapeInstance, (uint32_t)i, &getter, &setter, &param, &declaration))    // We crash here
	{
		const char* declarationData = (const char*)REALGetStringContents(declaration, &numBytes);

		OutputDebugStringA(declarationData);

		if (strcmp(declarationData, "ArcAngle") == 0)
		{
			ArcAngleSetter = (void (*)(REALobject, RBInteger, double))setter;
		}
		else if (strcmp(declarationData, "StartAngle") == 0)
		{
			StartAngleSetter = (void (*)(REALobject, RBInteger, double))setter;
		}

		//REALUnlockString(declaration);  // I got this commented out for now but I was not sure if we supposed to unlock here or not.
	}

	OutputDebugStringA("After the if check.....");  // We do not come here
}

For which value of I does it crash?

I have this working in my code:

void *FindPropertyGetter(REALobject o, const char* propDeclaration, bool WantSetter)
{
	if (o)
	{
		RBInteger propCount = REALCountClassProperties(o);
		DebugMessage("propCount", propCount);
		
		for (RBInteger i = 0; i < propCount; I++)
		{
			void *getter = nil;
			void *setter = nil;
			long param = 0;
			REALstring declaration = nil;
			RBBoolean r = REALGetClassProperty(o, i, &getter, &setter, &param, &declaration);
			FreeLater(declaration);
			
			if (r)
			{
				rbText t(declaration);
				if (strcmp(t.GetUTF8(), propDeclaration) == 0)
				{
					if (WantSetter)
						return setter;
					return getter;
				}
			}
		}

and it looks very similar.

Hmmmmm yes looks very much the same.

For me it crashes on first call to REALGetClassProperty for instance of ArcShape object.

And it crashes on the call it self to the REALGetClassProperty.

I guess I could try setting the getter and setters to nil, since thats the only diff I see.

Thanks

Yes it works !

I set the getter, setter and declaration to nil, before the call and then everything works.

But this means there is feature there that we do not know about…since Xojo is doing something with the parameters as input and not just as output.

And its probably on the declaration REALstring parameter…possibly direct lookup by name ?

Strange. Maybe make an issue and reference this thread?

Maybe @William_Yu can look in the code of the framework?

Yes, please create an Issues for this, I’m a bit surprised that this function works the way it does. The declaration parameter is definitely the fragile component in this situation.

I also found that the declaration should not be unlocked. But if its unlocked then you eventually crash due to string reference count problem.

(Which contradicts Christians code)

But that unlock was in the example code I got from William years ago :wink:

So maybe a bug?

Very possibly

I am just reporting my findings from having done extensive tests on the thing today.