Advertisement

asCScriptEngine::FindNewOwnerForSharedType not handling template instances

Started by April 02, 2020 06:11 PM
4 comments, last by WitchLord 4 years, 7 months ago

The “asCModule::InternalReset()” function seems to correctly try finding new owners for template instances:

asCObjectType *type = templateInstances[n];
if( engine->FindNewOwnerForSharedType(type, this) != this ) …

but “asCScriptEngine::FindNewOwnerForSharedType” seems to be missing a case to handle this.
It looks like there should be an extra “else if” added:

int foundIdx = -1;
asCModule *mod = scriptModules[n];
if( mod == in_type->module ) continue;
if( in_type->flags & asOBJ_ENUM )
    foundIdx = mod->enumTypes.IndexOf(CastToEnumType(in_type));
else if (in_type->flags & asOBJ_TYPEDEF)
    foundIdx = mod->typeDefs.IndexOf(CastToTypedefType(in_type));
else if (in_type->flags & asOBJ_FUNCDEF)
    foundIdx = mod->funcDefs.IndexOf(CastToFuncdefType(in_type));
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
else if(in_type->flags & asOBJ_TEMPLATE)
    foundIdx = mod->templateInstances.IndexOf(CastToObjectType(in_type));
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
else
    foundIdx = mod->classTypes.IndexOf(CastToObjectType(in_type));

Forgot to mention that I came across this when the same array template types (the standard plugin array) were used in different modules and the type got cleaned up while being used in another module.
Can try making a crash example if the script engine is expected to work without those extra lines

Advertisement

Thanks. You're probably right.

If you can make a sample to reproduce the problem it would really save me some time (which is something I'm truly short on at the moment).

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

@witchlord Sorry, never mind. This exact change has already been made in newer versions on the script engine. I'm simply still using 2.32 and forgot to check if this was fixed

OK. No problem. Thanks for letting me know.

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