Advertisement

Proper way to update scripted objects?

Started by August 01, 2011 10:11 PM
12 comments, last by WitchLord 13 years, 3 months ago

Are you calling AddRef on the asIScriptObject that you create? If you don't the object will be destroyed before it is time, and this can very well crash the GC.


Yes I am.


void Object::doCreate()
{
int id = scrType->GetFactoryIdByDecl( "ObjectController @ObjectController( Object @object)");
assert( id >= 0);
asIScriptContext *context = scriptEngine->GetContext();

if (context != NULL)
{
context->Prepare( id);
*((Object**)context->GetAddressOfArg(0)) = this;
AddRef();

int r = context->Execute();

if (r != asEXECUTION_FINISHED)
{
if (r == asEXECUTION_EXCEPTION)
{
const char *exception = context->GetExceptionString();
printf( "An Exception 's%' Occured In The Create Event.\n", exception);
return;
}

if (r == asERROR)
{
printf( "An Unexpected Error Occured In The Create Event.\n");
return;
}
}
else
{
scrObj = *(asIScriptObject**) context->GetAddressOfReturnValue();
scrObj->AddRef();

createCalled = true;
}
}
}
Indeed. Your code looks to be correct.

Is it possible to isolate under what circumstances the crash happens? It might be a problem in AngelScript, but I need help in finding a way to reproduce it. For example does the crash happen if you shut down the application right after creating the object without making any further script calls?

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

Indeed. Your code looks to be correct.

Is it possible to isolate under what circumstances the crash happens? It might be a problem in AngelScript, but I need help in finding a way to reproduce it. For example does the crash happen if you shut down the application right after creating the object without making any further script calls?


The crash happens only when doCreate() is called, even if no other script calls were made. If doCreate() is not called it closes fine, but thats almost the same as not creating a object at all in my case.

EDIT:

After further debugging I found that something is causing the object type's module to become invalid (0xfeefee). I have a lucky guess that's what causing this.
Hmm.

What does your script class look like?

Is the script context properly released?

Is the scrObj released after you release the script engine?

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