Advertisement

Heap Corruption When Using Misregistered Global Objects.

Started by March 04, 2012 08:30 PM
2 comments, last by WitchLord 12 years, 8 months ago
I recently ran into a problem that was solved by changing the way I register global objects.

Consider:


ResourceType* someResource = new ResourceType(resourceData);

string decl("ImageResource@ APPREGISTERED_"+resourceName);

pScriptEngine->RegisterGlobalProperty(decl.c_str(),someResource);

// Then in script.
Frame@ frame1 = APPREGISTERED_SomeResource.GetFrame("some_valid_frame_in_the_resource0001"); // C-C-C-C-CRASH!

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This won't crash, however.
string decl("ImageResource APPREGISTERED_"+resourceName);
pScriptEngine->RegisterGlobalProperty(decl.c_str(),someResource);

// Then in script.
Frame@ frame1 = APPREGISTERED_SomeResource.GetFrame("some_valid_frame_in_the_resource0001"); // This does not crash.


Could this possibly be a bug within AngelScript? Perhaps a script warning is in order?
Rantings, ravings, and occasional insight from your typical code-monkey: http://angryprogrammingprimate.blogspot.com/
No, it's not a bug. Unfortunately there is no way for AngelScript to know you've registered the global property with an incorrect pointer, so it's not possible to warn about it.

In the first case you should have registered the property with a pointer to a pointer, since you gave the declaration as a handle. The crash happened because AngelScript tried to dereference the pointer to access the handle.

In the second case you did it right, i.e you registered it with a pointer to the object and the declaration as the direct object.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Alright. Maybe bringing this up in the documentation might help others?
Rantings, ravings, and occasional insight from your typical code-monkey: http://angryprogrammingprimate.blogspot.com/
Manual: Registering global properties

It's already there, but I'll see if I can make it more explicit in the article.

Thanks,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement