瀏覽代碼

Fix constant access in base class through subclass instance

Fixes as issue where a subclass calls a base class method that tries to access a constant from the script.
The original code went through every ower class, and for each owner, went through its inheritance tree.
This seems like the wrong order, the modified code goes to each base class, and for each base class goes through the owner tree.
This is more in line with what the parser does, as the current impelemtation allows an access that the parser does not support.
This change should not negatively affect existing code due to the way the parser works
ChibiDenDen 5 年之前
父節點
當前提交
9ffa9a6bac
共有 1 個文件被更改,包括 7 次插入7 次删除
  1. 7 7
      modules/gdscript/gdscript_function.cpp

+ 7 - 7
modules/gdscript/gdscript_function.cpp

@@ -67,23 +67,23 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta
 		case ADDR_TYPE_CLASS_CONSTANT: {
 		case ADDR_TYPE_CLASS_CONSTANT: {
 
 
 			//todo change to index!
 			//todo change to index!
-			GDScript *o = p_script;
+			GDScript *s = p_script;
 #ifdef DEBUG_ENABLED
 #ifdef DEBUG_ENABLED
 			ERR_FAIL_INDEX_V(address, _global_names_count, NULL);
 			ERR_FAIL_INDEX_V(address, _global_names_count, NULL);
 #endif
 #endif
 			const StringName *sn = &_global_names_ptr[address];
 			const StringName *sn = &_global_names_ptr[address];
 
 
-			while (o) {
-				GDScript *s = o;
-				while (s) {
+			while (s) {
+				GDScript *o = s;
+				while (o) {
 
 
-					Map<StringName, Variant>::Element *E = s->constants.find(*sn);
+					Map<StringName, Variant>::Element *E = o->constants.find(*sn);
 					if (E) {
 					if (E) {
 						return &E->get();
 						return &E->get();
 					}
 					}
-					s = s->_base;
+					o = o->_owner;
 				}
 				}
-				o = o->_owner;
+				s = s->_base;
 			}
 			}
 
 
 			ERR_FAIL_V_MSG(NULL, "GDScriptCompiler bug.");
 			ERR_FAIL_V_MSG(NULL, "GDScriptCompiler bug.");