Hi. I am wondering how its recommended I deal with function ref counts. I am getting some cleanup errors on ref
counts.
(0:0) Object {107}. GC cannot destroy an object of type '_builtin_function_' as it can't see all references. Current ref count is 1.
(0:0) The builtin type in previous message is named 'InventoryClosedCallback'
Mainly I am wondering if 'module->GetFunctionByName()' adds a refcount to the function it returns?
Should I be addref'ing what it returns before storing it? Should I release on program cleanup? Or should I just let angelscript handle all the ref counts for functions and not touch them?
Currently I have:
asIScriptModule *module = scriptEngine->GetModule(moduleNameAscii.c_str());
asIScriptFunction *func = module->GetFunctionByName(functionNameAscii.c_str());
func->AddRef();
AddScriptCallback(func)
AddScriptCallback just adds it to a vector of asIScriptFunction*, who get release() called on them on program exit (Before anglescript is cleaned up however)
if I remove the func->AddRef, angelscript crashes in asCModule::~asCModule() Line 68, called from asCScriptEngine::~asCScriptEngine() Line 559 (ie, as angelscript shuts down)
It also appears that when Angelscript calls a function similar to AddScriptCallback that the func does indeed have 1 extra ref. I assume that is because I pass it by @ handle.
void Player::AddItemCallback(ScriptCallback::CallbackSource callbackSource, asIScriptFunction *func, unsigned int callbackData)
{
ScriptCallback newCallback;
newCallback.mCallback = func;
newCallback.mCallbackData = callbackData;
newCallback.mCallbackSource = callbackSource;
mScriptCallbacks.Add(newCallback);
}
r = scriptEngine->RegisterObjectMethod("Player", "void AddItemCallback(CallbackSource,ItemCallback @,uint)", asMETHOD(Player,AddItemCallback), asCALL_THISCALL); assert( r >= 0 );
that results in angelscript not complaining about any GC cleanup errors.