overte-org / overte

Overte open source virtual worlds platform.
https://overte.org/
Other
127 stars 47 forks source link

Unhandled C++ exception in scriptContentAvilable when changing domains #1036

Closed ksuprynowicz closed 5 days ago

ksuprynowicz commented 1 week ago

It happens when script loads after script engine has already been deleted:

terminate called after throwing an instance of 'std::bad_weak_ptr'
  what():  bad_weak_ptr

Backtrace:

__pthread_kill_implementation 0x00007ffff04a816c
operator() ScriptManager.cpp:2057
ScriptCache::scriptContentAvailable ScriptCache.cpp:215
operator() ScriptCache.cpp:128
Application::notify Application.cpp:4292
main main.cpp:776

Source code:

            std::shared_ptr<ScriptManager> strongRef(weakRef);
            if (!strongRef) {
                qCWarning(scriptengine) << "loadEntityScript.contentAvailable -- ScriptManager was deleted during getScriptContents!!";
                return;
ksuprynowicz commented 1 week ago

The issue in the code is that if weakRef is not valid, std::shared_ptr constructor throws an exception instead of making a null shared pointer like our code expects. Using lock() method instead will fix this. We should audit code and find all such occurences.