Jump to content
  • Advertisement
Sign in to follow this  
3kimr

Heap Corruption When Using Misregistered Global Objects.

This topic is 2478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!