This code that used to work in the previous version of AngelScript now returns a null pointer since updating to version 2.27.0. It's pretty much identical to what's in the manual, so I'm wondering if the method for getting the object pointer has changed since the update.
void Object::CallConstructor()
{
if (constructorCalled)
return;
asIScriptContext *context = scriptManager->GetContext();
if (context == NULL)
return;
if (context->Prepare( funcConstructor) < 0)
{
printf( "There was an error preparing the context.\n");
return;
}
*((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', Occurred In The Constructor.\n", exception);
return;
}
if (r == asERROR)
{
printf( "An Unexpected Error Occurred In The Constructor.\n");
return;
}
}
else
{
pScrObj = *((asIScriptObject**)context->GetAddressOfReturnValue());// <---------------------
pScrObj->AddRef(); //Must Be Called or else Pure Virtual Error!
context->Unprepare();
constructorCalled = true;
}
}