Basically I have a garbage collected class that inherits from this helper class
class asGarbageCollected{public: virtual ~asGarbageCollected(){} void SetGCFlag() { ref_count |= 0x80000000; } bool GetGCFlag() { return (ref_count & 0x80000000) ? true : false; } int GetRefCount() { return (ref_count & 0x7FFFFFFF); } virtual void EnumReferences()=0; void AddRef() { ref_count = (ref_count&0x7FFFFFFF) + 1; } void Release() { ref_count &= 0x7FFFFFFF; if( --ref_count == 0 ) delete this; } virtual void ReleaseAllReferences()=0;protected: int ref_count; asIScriptEngine* engine; // set by the inherited class.};
However, when the garbage collector runs its cycle, it segfaults. Here's the callstack as reported by GDB
#0 00000000 0x00000051 in ??() (??:??)#1 0044AC24 asCScriptEngine::CallObjectMethod(this=0x2bdf9e8, obj=0x2c03378, param=0x2bdf9e8, i=0x2bf2058, s=0x2bf20a8) (../../source/as_scriptengine.cpp:3179)#2 0044AAE9 asCScriptEngine::CallObjectMethod(this=0x2bdf9e8, obj=0x2c03378, param=0x2bdf9e8, func=152) (../../source/as_scriptengine.cpp:3159)#3 0046021E asCGarbageCollector::IdentifyGarbageWithCyclicRefs(this=0x2be0070) (../../source/as_gc.cpp:355)#4 0045FBEB asCGarbageCollector::GarbageCollect(this=0x2be0070, flags=1) (../../source/as_gc.cpp:90)#5 0044AFA3 asCScriptEngine::GarbageCollect(this=0x2bdf9e8, flags=1) (../../source/as_scriptengine.cpp:3284)#6 0041F4BF mengi::Stage::Run(this=0x2bdf878) (C:/Documents and Settings/orm/Desktop/mengi/engine/src/Stage.cpp:498)#7 0041E4F3 mengi::Stage::Update(this=0x2bdf878, t=2.50237131) (C:/Documents and Settings/orm/Desktop/mengi/engine/src/Stage.cpp:371)#8 0040FA86 mengi::Engine::Run(this=0x2ae5e48) (C:/Documents and Settings/orm/Desktop/mengi/engine/src/Engine.cpp:325)#9 004352BE main(argc=1, argv=0x2ae4588) (C:/Documents and Settings/orm/Desktop/mengi/engine/src/main.cpp:7)
I'll post more info from valgrind when i get back to my linux machine, because I doubt this is limited to just windows (building from svn)