I am only adding a single reference to my script object on the application side (during construction where I instantiate it).
And during the application side object's destruct or, I call release() on that same Script object.
There are no script side objects holding or adding references to it either, and yet, when I call release it has between 1 and 2 references left :/
What else could be adding references to it?
I call a few methods on it, but nothing takes it as an argument or anything like that.
*edit*
I just noticed, after constructing my script object, I add a reference to it for my application, and right then it already has 3. Why is that?
*edit* *edit*
Ah I found the engine ReleaseScriptObject() method, so now my cleanup looks like this:
asIScriptEngine* engine = m_scriptObject->GetEngine();
engine->ReleaseScriptObject( m_scriptObject,m_scriptObject->GetTypeId() );
m_scriptObject->Release();
And this *works* but is this how it is intended to be done?
*edit* *edit* *edit*
Well, while the above method seems to work, when the script engine is cleaned up at the end of the program (it is held by a global, so it happens when globals are being cleaned up at the end), I get a crash, leading me to believe maybe this isn't how I should be cleaning up these script objects.
This is how I clean things up at the end:
ScriptEngine::~ScriptEngine() {
m_context->Release();
m_engine->Release();
}
And this is the stack trace I get when it crashes:
Quote:
#0 0052B155 asCScriptEngine::CallObjectMethod(this=0x2c83d00, obj=0x64e2288, i=0x2c86320, s=0x2c86550) (C:/code/libraries/AngelScript_svn/sdk/angelscript/source/as_scriptengine.cpp:2867)
#1 0052B1FF asCScriptEngine::CallObjectMethod(this=0x2c83d00, obj=0x64e2288, func=16) (C:/code/libraries/AngelScript_svn/sdk/angelscript/source/as_scriptengine.cpp:2839)
#2 00548F24 asCGarbageCollector::IdentifyGarbageWithCyclicRefs(this=0x2c8401c) (C:/code/libraries/AngelScript_svn/sdk/angelscript/source/as_gc.cpp:298)
#3 0054979D asCGarbageCollector::GarbageCollect(this=0x2c8401c, flags=asGC_FULL_CYCLE) (C:/code/libraries/AngelScript_svn/sdk/angelscript/source/as_gc.cpp:90)
#4 0052A184 asCScriptEngine::GarbageCollect(this=0x2c83d00, flags=asGC_FULL_CYCLE) (C:/code/libraries/AngelScript_svn/sdk/angelscript/source/as_scriptengine.cpp:3191)
#5 0053564C asCScriptEngine::Reset(this=0x2c83d00) (C:/code/libraries/AngelScript_svn/sdk/angelscript/source/as_scriptengine.cpp:519)
#6 00536F26 asCScriptEngine::~asCScriptEngine(this=0x2c83d00) (C:/code/libraries/AngelScript_svn/sdk/angelscript/source/as_scriptengine.cpp:361)
#7 0053584F asCScriptEngine::Release(this=0x2c83d00) (C:/code/libraries/AngelScript_svn/sdk/angelscript/source/as_scriptengine.cpp:496)
#8 004314BA ScriptEngine::~ScriptEngine(this=0x742520) (C:/code/TowerDefense/TowerDefenseCommon/ScriptEngine.cpp:159)
#9 00432DC2 __static_initialization_and_destruction_0(__initialize_p=0, __priority=65535) (C:/code/TowerDefense/TowerDefenseCommon/ScriptEngine.cpp:14)
#10 00432DE5 global destructors keyed to gScriptEngine() (C:/code/TowerDefense/TowerDefenseCommon/ScriptEngine.cpp:357)
#11 005B8132 __do_global_dtors() (./boost/system/error_code.hpp:212)
#12 761C1FEF msvcrt!_flushall() (C:\Windows\syswow64\msvcrt.dll:??)
#13 00000000 0x3923e76b in ??() (??:??)
#14 00000000 0x00000000 in ??() (??:??)
any ideas?
[Edited by - Wavesonics on May 21, 2009 7:00:22 PM]