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));