Hi,
I got these strange errors in my application:
[SCRIPT] [ERROR] (0, 0) : Object {245683}. GC cannot destroy an object of type '�t|' as it doesn't know how many references to there are.
[SCRIPT] [ERROR] (0, 0) : Object {245593}. GC cannot destroy an object of type '�t|' as it doesn't know how many references to there are.
[SCRIPT] [ERROR] (0, 0) : Object {245677}. GC cannot destroy an object of type '�t|' as it doesn't know how many references to there are.
The type string is always different. And Valgrind says this:
==29943== Invalid read of size 4
==29943== at 0x5188E00: asCAtomic::get() const (as_atomic.cpp:52)
==29943== by 0x51A1761: asCScriptEngine::CallObjectMethodRetInt(void*, int) const (as_scriptengine.cpp:4203)
==29943== by 0x5192A71: asCGarbageCollector::DestroyOldGarbage() (as_gc.cpp:564)
==29943== by 0x519370D: asCGarbageCollector::GarbageCollect(unsigned int, unsigned int) (as_gc.cpp:238)
==29943== by 0x519DD03: asCScriptEngine::GarbageCollect(unsigned int, unsigned int) (as_scriptengine.cpp:4636)
==29943== by 0x5190261: asCContext::Execute() (as_context.cpp:1356)
==29943== by 0x4FDF9A4: RunScriptMethod<void> (ScriptExecutor.h:196)
==29943== by 0x4FDF9A4: Leviathan::ScriptSystemWrapper::CreateAndDestroyNodes() (ScriptSystemWrapper.cpp:134)
==29943== by 0x4FD2D28: Leviathan::GameWorld::HandleAddedAndDeleted() (GameWorld.cpp:593)
==29943== by 0x4FF09A5: Leviathan::StandardWorld::HandleAddedAndDeleted() (StandardWorld.cpp:690)
==29943== by 0x4FD87F3: Leviathan::GameWorld::Tick(int) (GameWorld.cpp:528)
==29943== by 0x4FA1F1E: Leviathan::Engine::Tick() (Engine.cpp:895)
==29943== by 0x507FB0F: Leviathan::LeviathanApplication::RunMessageLoop() (Application.cpp:137)
==29943== Address 0x9e2a2c40 is 16 bytes inside a block of size 148 free'd
==29943== at 0x4C2FDAC: free (vg_replace_malloc.c:530)
==29943== by 0x51AE63A: asCScriptObject::Release() const (as_scriptobject.cpp:647)
==29943== by 0x51A1120: asCScriptEngine::CallObjectMethod(void*, asSSystemFunctionInterface*, asCScriptFunction*) const (as_scriptengine.cpp:4050)
==29943== by 0x518FE03: asCContext::ExecuteNext() (as_context.cpp:2813)
==29943== by 0x519011C: asCContext::Execute() (as_context.cpp:1324)
==29943== by 0x50296FC: Leviathan::ScriptRunResult<int> Leviathan::ScriptExecutor::RunScriptMethod<int, Leviathan::GenericEvent*&>(Leviathan::ScriptRunningSetup&, asIScriptFunction*, void*, Leviathan::GenericEvent*&) (ScriptExecutor.h:196)
==29943== by 0x502BF2A: non-virtual thunk to Leviathan::Script::EventListener::OnGenericEvent(Leviathan::GenericEvent*) (new_allocator.h:125)
==29943== by 0x50724CC: Leviathan::EventHandler::CallEvent(Leviathan::GenericEvent*) (EventHandler.cpp:65)
==29943== by 0x50608DA: CallEvent (EventHandler.h:38)
==29943== by 0x50608DA: Leviathan::GUI::View::OnProcessMessageReceived(scoped_refptr<CefBrowser>, cef_process_id_t, scoped_refptr<CefProcessMessage>) (GuiView.cpp:860)
==29943== by 0x51328D6: (anonymous namespace)::client_on_process_message_received(_cef_client_t*, _cef_browser_t*, cef_process_id_t, _cef_process_message_t*) (client_cpptoc.cc:264)
==29943== by 0x77EC397: ??? (in /home/hhyyrylainen/Projects/thrive/build/bin/lib/libcef.so)
==29943== by 0x93A7639: ??? (in /home/hhyyrylainen/Projects/thrive/build/bin/lib/libcef.so)
==29943== Block was alloc'd at
==29943== at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
==29943== by 0x518FA79: asCContext::ExecuteNext() (as_context.cpp:2710)
==29943== by 0x519011C: asCContext::Execute() (as_context.cpp:1324)
==29943== by 0x50296FC: Leviathan::ScriptRunResult<int> Leviathan::ScriptExecutor::RunScriptMethod<int, Leviathan::GenericEvent*&>(Leviathan::ScriptRunningSetup&, asIScriptFunction*, void*, Leviathan::GenericEvent*&) (ScriptExecutor.h:196)
==29943== by 0x502BF2A: non-virtual thunk to Leviathan::Script::EventListener::OnGenericEvent(Leviathan::GenericEvent*) (new_allocator.h:125)
==29943== by 0x50724CC: Leviathan::EventHandler::CallEvent(Leviathan::GenericEvent*) (EventHandler.cpp:65)
==29943== by 0x50608DA: CallEvent (EventHandler.h:38)
==29943== by 0x50608DA: Leviathan::GUI::View::OnProcessMessageReceived(scoped_refptr<CefBrowser>, cef_process_id_t, scoped_refptr<CefProcessMessage>) (GuiView.cpp:860)
==29943== by 0x51328D6: (anonymous namespace)::client_on_process_message_received(_cef_client_t*, _cef_browser_t*, cef_process_id_t, _cef_process_message_t*) (client_cpptoc.cc:264)
==29943== by 0x77EC397: ??? (in /home/hhyyrylainen/Projects/thrive/build/bin/lib/libcef.so)
==29943== by 0x93A7639: ??? (in /home/hhyyrylainen/Projects/thrive/build/bin/lib/libcef.so)
==29943== by 0x93A747D: ??? (in /home/hhyyrylainen/Projects/thrive/build/bin/lib/libcef.so)
==29943== by 0x93A6AA9: ??? (in /home/hhyyrylainen/Projects/thrive/build/bin/lib/libcef.so)
After looking for a minimal example that would cause an issue here, I think I got it (this doesn't lead to the same error, though):
class Organelle{
}
class PlacedOrganelle{
PlacedOrganelle(Organelle@ organelle)
{
@this.organelle = organelle;
}
Organelle@ organelle;
}
void RunTest()
{
PlacedOrganelle@ organelle = PlacedOrganelle(Organelle());
dictionary data;
// This alternative works
// @data["organelle"] = organelle;
// This causes errors
data["organelle"] = organelle;
PlacedOrganelle@ organelle2 = cast<PlacedOrganelle>(data["organelle"]);
}
The error that I get with that is:
[SCRIPT] [ERROR] (0, 0) : Failed in call to function 'CreateScriptObject' (Code: asNO_FUNCTION, -6)
And it goes away if I add "@" to the assignment into the dictionary. This same thing also fixes my full application so I think this is the same error in both even if the behavior is different.
Tested with revision 2547. I tried updating to see if there was a fix (I'd like to get a compile error with the incorrect code), but revision 2557 fails to compile with (this error repeats quite a few times):
In file included from /home/hhyyrylainen/Projects/Leviathan/build/ThirdParty/include/add_on/scriptmath/scriptmathcomplex.h:6,
from /home/hhyyrylainen/Projects/Leviathan/build/ThirdParty/include/add_on/scriptmath/scriptmathcomplex.cpp:5:
/home/hhyyrylainen/Projects/Leviathan/build/ThirdParty/include/add_on/scriptmath/scriptmathcomplex.cpp: Funktio ”void RegisterScriptMathComplex_Native(asIScriptEngine*)”:
/home/hhyyrylainen/Projects/Leviathan/build/ThirdParty/include/angelscript.h:421:62: virhe: cast from ”float*” to ”int” loses precision [-fpermissive]
#define asOFFSET(s,m) ((int)(&reinterpret_cast<s*>(100000)->m)-100000)
^
/home/hhyyrylainen/Projects/Leviathan/build/ThirdParty/include/add_on/scriptmath/scriptmathcomplex.cpp:177:59: huom: in expansion of macro ”asOFFSET”
r = engine->RegisterObjectProperty("complex", "float r", asOFFSET(Complex, r)); assert( r >= 0 );
^~~~~~~~
/home/hhyyrylainen/Projects/Leviathan/build/ThirdParty/include/angelscript.h:421:62: virhe: cast from ”float*” to ”int” loses precision [-fpermissive]
#define asOFFSET(s,m) ((int)(&reinterpret_cast<s*>(100000)->m)-100000)
^
/home/hhyyrylainen/Projects/Leviathan/build/ThirdParty/include/add_on/scriptmath/scriptmathcomplex.cpp:178:59: huom: in expansion of macro ”asOFFSET”
r = engine->RegisterObjectProperty("complex", "float i", asOFFSET(Complex, i)); assert( r >= 0 );
^~~~~~~~
I'm using "gcc (GCC) 8.2.1 20181011 (Red Hat 8.2.1-4)"