瀏覽代碼

Fix extends issue, closes #4026

Juan Linietsky 9 年之前
父節點
當前提交
565bb3afcc
共有 2 個文件被更改,包括 7 次插入1 次删除
  1. 3 1
      modules/gdscript/gd_compiler.cpp
  2. 4 0
      modules/gdscript/gd_script.cpp

+ 3 - 1
modules/gdscript/gd_compiler.cpp

@@ -1497,7 +1497,8 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
 					String sub = p_class->extends_class[i];
 					String sub = p_class->extends_class[i];
 					if (script->subclasses.has(sub)) {
 					if (script->subclasses.has(sub)) {
 
 
-						script=script->subclasses[sub];
+						Ref<Script> subclass = script->subclasses[sub]; //avoid reference from dissapearing
+						script=subclass;
 					} else {
 					} else {
 
 
 						_set_error("Could not find subclass: "+sub,p_class);
 						_set_error("Could not find subclass: "+sub,p_class);
@@ -1683,6 +1684,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
 		if (err)
 		if (err)
 			return err;
 			return err;
 
 
+
 		p_script->constants.insert(name,subclass); //once parsed, goes to the list of constants
 		p_script->constants.insert(name,subclass); //once parsed, goes to the list of constants
 		p_script->subclasses.insert(name,subclass);
 		p_script->subclasses.insert(name,subclass);
 
 

+ 4 - 0
modules/gdscript/gd_script.cpp

@@ -874,6 +874,10 @@ GDScript::~GDScript() {
 		memdelete( E->get() );
 		memdelete( E->get() );
 	}
 	}
 
 
+	for (Map<StringName,Ref<GDScript> >::Element *E=subclasses.front();E;E=E->next()) {
+		E->get()->_owner=NULL; //bye, you are no longer owned cause I died
+	}
+
 #ifdef DEBUG_ENABLED
 #ifdef DEBUG_ENABLED
 	if (GDScriptLanguage::get_singleton()->lock) {
 	if (GDScriptLanguage::get_singleton()->lock) {
 		GDScriptLanguage::get_singleton()->lock->lock();
 		GDScriptLanguage::get_singleton()->lock->lock();