@@ -396,6 +396,8 @@ bool GDScript::get_property_default_value(const StringName &p_property, Variant
396396}
397397
398398ScriptInstance *GDScript::instance_create (Object *p_this) {
399+ ERR_FAIL_COND_V_MSG (!valid, nullptr , " Script is invalid!" );
400+
399401 GDScript *top = this ;
400402 while (top->_base ) {
401403 top = top->_base ;
@@ -902,6 +904,11 @@ void GDScript::unload_static() const {
902904}
903905
904906Variant GDScript::callp (const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
907+ if (unlikely (!valid)) {
908+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
909+ return Variant ();
910+ }
911+
905912 GDScript *top = this ;
906913 while (top) {
907914 HashMap<StringName, GDScriptFunction *>::Iterator E = top->member_functions .find (p_method);
@@ -924,6 +931,10 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const {
924931 return true ;
925932 }
926933
934+ if (unlikely (!valid)) {
935+ return false ;
936+ }
937+
927938 const GDScript *top = this ;
928939 while (top) {
929940 {
@@ -980,6 +991,10 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
980991 return true ;
981992 }
982993
994+ if (unlikely (!valid)) {
995+ return false ;
996+ }
997+
983998 GDScript *top = this ;
984999 while (top) {
9851000 HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices .find (p_name);
@@ -1014,6 +1029,10 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
10141029void GDScript::_get_property_list (List<PropertyInfo> *p_properties) const {
10151030 p_properties->push_back (PropertyInfo (Variant::STRING, " script/source" , PROPERTY_HINT_NONE, " " , PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
10161031
1032+ if (unlikely (!valid)) {
1033+ return ;
1034+ }
1035+
10171036 List<const GDScript *> classes;
10181037 const GDScript *top = this ;
10191038 while (top) {
@@ -1630,6 +1649,10 @@ GDScript::~GDScript() {
16301649// ////////////////////////////
16311650
16321651bool GDScriptInstance::set (const StringName &p_name, const Variant &p_value) {
1652+ if (unlikely (!script->valid )) {
1653+ return false ;
1654+ }
1655+
16331656 {
16341657 HashMap<StringName, GDScript::MemberInfo>::Iterator E = script->member_indices .find (p_name);
16351658 if (E) {
@@ -1703,6 +1726,10 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
17031726}
17041727
17051728bool GDScriptInstance::get (const StringName &p_name, Variant &r_ret) const {
1729+ if (unlikely (!script->valid )) {
1730+ return false ;
1731+ }
1732+
17061733 {
17071734 HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = script->member_indices .find (p_name);
17081735 if (E) {
@@ -1823,6 +1850,10 @@ void GDScriptInstance::validate_property(PropertyInfo &p_property) const {
18231850}
18241851
18251852void GDScriptInstance::get_property_list (List<PropertyInfo> *p_properties) const {
1853+ if (unlikely (!script->valid )) {
1854+ return ;
1855+ }
1856+
18261857 // exported members, not done yet!
18271858
18281859 const GDScript *sptr = script.ptr ();
@@ -1901,6 +1932,10 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const
19011932}
19021933
19031934bool GDScriptInstance::property_can_revert (const StringName &p_name) const {
1935+ if (unlikely (!script->valid )) {
1936+ return false ;
1937+ }
1938+
19041939 Variant name = p_name;
19051940 const Variant *args[1 ] = { &name };
19061941
@@ -1921,6 +1956,10 @@ bool GDScriptInstance::property_can_revert(const StringName &p_name) const {
19211956}
19221957
19231958bool GDScriptInstance::property_get_revert (const StringName &p_name, Variant &r_ret) const {
1959+ if (unlikely (!script->valid )) {
1960+ return false ;
1961+ }
1962+
19241963 Variant name = p_name;
19251964 const Variant *args[1 ] = { &name };
19261965
@@ -1995,6 +2034,11 @@ void GDScriptInstance::_call_implicit_ready_recursively(GDScript *p_script) {
19952034}
19962035
19972036Variant GDScriptInstance::callp (const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
2037+ if (unlikely (!script->valid )) {
2038+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
2039+ return Variant ();
2040+ }
2041+
19982042 GDScript *sptr = script.ptr ();
19992043 if (unlikely (p_method == SceneStringName (_ready))) {
20002044 // Call implicit ready first, including for the super classes recursively.
@@ -2012,6 +2056,10 @@ Variant GDScriptInstance::callp(const StringName &p_method, const Variant **p_ar
20122056}
20132057
20142058void GDScriptInstance::notification (int p_notification, bool p_reversed) {
2059+ if (unlikely (!script->valid )) {
2060+ return ;
2061+ }
2062+
20152063 // notification is not virtual, it gets called at ALL levels just like in C.
20162064 Variant value = p_notification;
20172065 const Variant *args[1 ] = { &value };
0 commit comments