@@ -750,69 +750,87 @@ void ClassDB::set_object_extension_instance(Object *p_object, const StringName &
750
750
}
751
751
752
752
bool ClassDB::can_instantiate (const StringName &p_class) {
753
- OBJTYPE_RLOCK;
753
+ String script_path;
754
+ {
755
+ OBJTYPE_RLOCK;
754
756
755
- ClassInfo *ti = classes.getptr (p_class);
756
- if (!ti) {
757
- if (!ScriptServer::is_global_class (p_class)) {
758
- ERR_FAIL_V_MSG (false , vformat (" Cannot get class '%s'." , String (p_class)));
757
+ ClassInfo *ti = classes.getptr (p_class);
758
+ if (!ti) {
759
+ if (!ScriptServer::is_global_class (p_class)) {
760
+ ERR_FAIL_V_MSG (false , vformat (" Cannot get class '%s'." , String (p_class)));
761
+ }
762
+ script_path = ScriptServer::get_global_class_path (p_class);
763
+ goto use_script; // Open the lock for resource loading.
759
764
}
760
- String path = ScriptServer::get_global_class_path (p_class);
761
- Ref<Script> scr = ResourceLoader::load (path);
762
- return scr.is_valid () && scr->is_valid () && !scr->is_abstract ();
763
- }
764
765
#ifdef TOOLS_ENABLED
765
- if ((ti->api == API_EDITOR || ti->api == API_EDITOR_EXTENSION) && !Engine::get_singleton ()->is_editor_hint ()) {
766
- return false ;
767
- }
766
+ if ((ti->api == API_EDITOR || ti->api == API_EDITOR_EXTENSION) && !Engine::get_singleton ()->is_editor_hint ()) {
767
+ return false ;
768
+ }
768
769
#endif
769
- return _can_instantiate (ti);
770
+ return _can_instantiate (ti);
771
+ }
772
+
773
+ use_script:
774
+ Ref<Script> scr = ResourceLoader::load (script_path);
775
+ return scr.is_valid () && scr->is_valid () && !scr->is_abstract ();
770
776
}
771
777
772
778
bool ClassDB::is_abstract (const StringName &p_class) {
773
- OBJTYPE_RLOCK;
779
+ String script_path;
780
+ {
781
+ OBJTYPE_RLOCK;
774
782
775
- ClassInfo *ti = classes.getptr (p_class);
776
- if (!ti) {
777
- if (!ScriptServer::is_global_class (p_class)) {
778
- ERR_FAIL_V_MSG (false , vformat (" Cannot get class '%s'." , String (p_class)));
783
+ ClassInfo *ti = classes.getptr (p_class);
784
+ if (!ti) {
785
+ if (!ScriptServer::is_global_class (p_class)) {
786
+ ERR_FAIL_V_MSG (false , vformat (" Cannot get class '%s'." , String (p_class)));
787
+ }
788
+ script_path = ScriptServer::get_global_class_path (p_class);
789
+ goto use_script; // Open the lock for resource loading.
779
790
}
780
- String path = ScriptServer::get_global_class_path (p_class);
781
- Ref<Script> scr = ResourceLoader::load (path);
782
- return scr.is_valid () && scr->is_valid () && scr->is_abstract ();
783
- }
784
791
785
- if (ti->creation_func != nullptr ) {
786
- return false ;
787
- }
788
- if (!ti->gdextension ) {
789
- return true ;
790
- }
792
+ if (ti->creation_func != nullptr ) {
793
+ return false ;
794
+ }
795
+ if (!ti->gdextension ) {
796
+ return true ;
797
+ }
791
798
#ifndef DISABLE_DEPRECATED
792
- return ti->gdextension ->create_instance2 == nullptr && ti->gdextension ->create_instance == nullptr ;
799
+ return ti->gdextension ->create_instance2 == nullptr && ti->gdextension ->create_instance == nullptr ;
793
800
#else
794
- return ti->gdextension ->create_instance2 == nullptr ;
801
+ return ti->gdextension ->create_instance2 == nullptr ;
795
802
#endif // DISABLE_DEPRECATED
803
+ }
804
+
805
+ use_script:
806
+ Ref<Script> scr = ResourceLoader::load (script_path);
807
+ return scr.is_valid () && scr->is_valid () && scr->is_abstract ();
796
808
}
797
809
798
810
bool ClassDB::is_virtual (const StringName &p_class) {
799
- OBJTYPE_RLOCK;
811
+ String script_path;
812
+ {
813
+ OBJTYPE_RLOCK;
800
814
801
- ClassInfo *ti = classes.getptr (p_class);
802
- if (!ti) {
803
- if (!ScriptServer::is_global_class (p_class)) {
804
- ERR_FAIL_V_MSG (false , vformat (" Cannot get class '%s'." , String (p_class)));
815
+ ClassInfo *ti = classes.getptr (p_class);
816
+ if (!ti) {
817
+ if (!ScriptServer::is_global_class (p_class)) {
818
+ ERR_FAIL_V_MSG (false , vformat (" Cannot get class '%s'." , String (p_class)));
819
+ }
820
+ script_path = ScriptServer::get_global_class_path (p_class);
821
+ goto use_script; // Open the lock for resource loading.
805
822
}
806
- String path = ScriptServer::get_global_class_path (p_class);
807
- Ref<Script> scr = ResourceLoader::load (path);
808
- return scr.is_valid () && scr->is_valid () && scr->is_abstract ();
809
- }
810
823
#ifdef TOOLS_ENABLED
811
- if ((ti->api == API_EDITOR || ti->api == API_EDITOR_EXTENSION) && !Engine::get_singleton ()->is_editor_hint ()) {
812
- return false ;
813
- }
824
+ if ((ti->api == API_EDITOR || ti->api == API_EDITOR_EXTENSION) && !Engine::get_singleton ()->is_editor_hint ()) {
825
+ return false ;
826
+ }
814
827
#endif
815
- return (_can_instantiate (ti) && ti->is_virtual );
828
+ return (_can_instantiate (ti) && ti->is_virtual );
829
+ }
830
+
831
+ use_script:
832
+ Ref<Script> scr = ResourceLoader::load (script_path);
833
+ return scr.is_valid () && scr->is_valid () && scr->is_abstract ();
816
834
}
817
835
818
836
void ClassDB::_add_class2 (const StringName &p_class, const StringName &p_inherits) {
0 commit comments