@@ -170,7 +170,7 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
170170 /* STEP 2, INITIALIZE AND CONSTRUCT */
171171 {
172172 MutexLock lock (GDScriptLanguage::singleton->mutex );
173- instances.insert ( instance->owner );
173+ instances.add (& instance->script_instance_list );
174174 }
175175
176176 _super_implicit_constructor (this , instance, r_error);
@@ -180,7 +180,7 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
180180 instance->owner ->set_script_instance (nullptr );
181181 {
182182 MutexLock lock (GDScriptLanguage::singleton->mutex );
183- instances.erase (p_owner );
183+ instances.remove (&instance-> script_instance_list );
184184 }
185185 ERR_FAIL_V_MSG (nullptr , " Error constructing a GDScriptInstance: " + error_text);
186186 }
@@ -198,7 +198,7 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
198198 instance->owner ->set_script_instance (nullptr );
199199 {
200200 MutexLock lock (GDScriptLanguage::singleton->mutex );
201- instances.erase (p_owner );
201+ instances.remove (&instance-> script_instance_list );
202202 }
203203 ERR_FAIL_V_MSG (nullptr , " Error constructing a GDScriptInstance: " + error_text);
204204 }
@@ -436,9 +436,12 @@ PlaceHolderScriptInstance *GDScript::placeholder_instance_create(Object *p_this)
436436}
437437
438438bool GDScript::instance_has (const Object *p_this) const {
439- MutexLock lock (GDScriptLanguage::singleton-> mutex );
439+ GDScriptInstance *instance = dynamic_cast <GDScriptInstance *>(p_this-> get_script_instance () );
440440
441- return instances.has ((Object *)p_this);
441+ if (instance == nullptr ) {
442+ return false ;
443+ }
444+ return instance->script .ptr () == this ;
442445}
443446
444447bool GDScript::has_source_code () const {
@@ -750,7 +753,7 @@ Error GDScript::reload(bool p_keep_state) {
750753 {
751754 MutexLock lock (GDScriptLanguage::singleton->mutex );
752755
753- has_instances = instances.size () ;
756+ has_instances = instances.first () != nullptr ;
754757 }
755758
756759 // Check condition but reset flag before early return
@@ -2045,8 +2048,8 @@ GDScriptInstance::~GDScriptInstance() {
20452048 }
20462049 }
20472050
2048- if (script.is_valid () && owner ) {
2049- script->instances .erase (owner );
2051+ if (script.is_valid ()) {
2052+ script->instances .remove (&script_instance_list );
20502053 }
20512054}
20522055
@@ -2472,15 +2475,13 @@ void GDScriptLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload
24722475 // save state and remove script from instances
24732476 HashMap<ObjectID, List<Pair<StringName, Variant>>> &map = to_reload[scr];
24742477
2475- while (scr->instances .front ()) {
2476- Object *obj = scr->instances .front ()->get ();
2478+ while (scr->instances .first ()) {
2479+ GDScriptInstance *instance = scr->instances .first ()->self ();
24772480 // save instance info
24782481 List<Pair<StringName, Variant>> state;
2479- if (obj->get_script_instance ()) {
2480- obj->get_script_instance ()->get_property_state (state);
2481- map[obj->get_instance_id ()] = state;
2482- obj->set_script (Variant ());
2483- }
2482+ instance->get_property_state (state);
2483+ map[instance->get_owner ()->get_instance_id ()] = state;
2484+ instance->get_owner ()->set_script (Variant ());
24842485 }
24852486
24862487 // same thing for placeholders
0 commit comments