فهرست منبع

Clear pending function states when reloading GDScript

(cherry picked from commit 53af7ee48296d7e39547169574b8ec6f24ba38eb)
Haoyu Qiu 3 سال پیش
والد
کامیت
cf04c46a5e
2فایلهای تغییر یافته به همراه14 افزوده شده و 8 حذف شده
  1. 13 8
      modules/gdscript/gdscript.cpp
  2. 1 0
      modules/gdscript/gdscript.h

+ 13 - 8
modules/gdscript/gdscript.cpp

@@ -77,6 +77,17 @@ Object *GDScriptNativeClass::instance() {
 	return ClassDB::instance(name);
 }
 
+void GDScript::_clear_pending_func_states() {
+	GDScriptLanguage::get_singleton()->lock.lock();
+	while (SelfList<GDScriptFunctionState> *E = pending_func_states.first()) {
+		// 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();
+	}
+	GDScriptLanguage::get_singleton()->lock.unlock();
+}
+
 GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error) {
 	/* STEP 1, CREATE */
 
@@ -597,6 +608,7 @@ Error GDScript::reload(bool p_keep_state) {
 	for (Map<StringName, Ref<GDScript>>::Element *E = subclasses.front(); E; E = E->next()) {
 		_set_subclass_path(E->get(), path);
 	}
+	_clear_pending_func_states();
 
 	return OK;
 }
@@ -923,14 +935,7 @@ void GDScript::_save_orphaned_subclasses() {
 }
 
 GDScript::~GDScript() {
-	GDScriptLanguage::get_singleton()->lock.lock();
-	while (SelfList<GDScriptFunctionState> *E = pending_func_states.first()) {
-		// 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();
-	}
-	GDScriptLanguage::get_singleton()->lock.unlock();
+	_clear_pending_func_states();
 
 	for (Map<StringName, GDScriptFunction *>::Element *E = member_functions.front(); E; E = E->next()) {
 		memdelete(E->get());

+ 1 - 0
modules/gdscript/gdscript.h

@@ -112,6 +112,7 @@ class GDScript : public Script {
 	SelfList<GDScript> script_list;
 
 	SelfList<GDScriptFunctionState>::List pending_func_states;
+	void _clear_pending_func_states();
 
 	GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error);