Merge pull request #97464 from Capital-EX/backport-65910-3.x
Some checks failed
🔗 GHA / 📊 Static (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🌐 JavaScript (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / ☁ Server (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled

[3.x] Backport "Cleanup function state connections when destroying instance" for Godot 3
This commit is contained in:
lawnjelly 2024-10-28 07:10:22 +00:00 committed by GitHub
commit 373075f3f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 2 deletions

View File

@ -83,7 +83,12 @@ void GDScript::_clear_pending_func_states() {
// Order matters since clearing the stack may already cause
// the GDSCriptFunctionState to be destroyed and thus removed from the list.
pending_func_states.remove(E);
E->self()->_clear_stack();
GDScriptFunctionState *state = E->self();
ObjectID state_id = state->get_instance_id();
state->_clear_connections();
if (ObjectDB::get_instance(state_id)) {
state->_clear_stack();
}
}
GDScriptLanguage::get_singleton()->lock.unlock();
}
@ -1372,7 +1377,12 @@ GDScriptInstance::~GDScriptInstance() {
// Order matters since clearing the stack may already cause
// the GDSCriptFunctionState to be destroyed and thus removed from the list.
pending_func_states.remove(E);
E->self()->_clear_stack();
GDScriptFunctionState *state = E->self();
ObjectID state_id = state->get_instance_id();
state->_clear_connections();
if (ObjectDB::get_instance(state_id)) {
state->_clear_stack();
}
}
if (script.is_valid() && owner) {

View File

@ -1855,6 +1855,15 @@ void GDScriptFunctionState::_clear_stack() {
}
}
void GDScriptFunctionState::_clear_connections() {
List<Object::Connection> conns;
get_signals_connected_to_this(&conns);
for (List<Object::Connection>::Element *E = conns.front(); E; E = E->next()) {
Object::Connection &c = E->get();
c.source->disconnect(c.signal, c.target, c.method);
}
}
void GDScriptFunctionState::_bind_methods() {
ClassDB::bind_method(D_METHOD("resume", "arg"), &GDScriptFunctionState::resume, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("is_valid", "extended_check"), &GDScriptFunctionState::is_valid, DEFVAL(false));

View File

@ -375,6 +375,7 @@ public:
Variant resume(const Variant &p_arg = Variant());
void _clear_stack();
void _clear_connections();
GDScriptFunctionState();
~GDScriptFunctionState();