diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/assimp/import_utils.h | 2 | ||||
-rw-r--r-- | modules/gdscript/gdscript.cpp | 51 | ||||
-rw-r--r-- | modules/gdscript/gdscript.h | 7 | ||||
-rw-r--r-- | modules/gdscript/gdscript_compiler.cpp | 10 | ||||
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 18 | ||||
-rw-r--r-- | modules/gdscript/gdscript_function.h | 22 | ||||
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 51 | ||||
-rw-r--r-- | modules/mono/csharp_script.cpp | 17 | ||||
-rw-r--r-- | modules/websocket/doc_classes/WebSocketServer.xml | 2 |
9 files changed, 125 insertions, 55 deletions
diff --git a/modules/assimp/import_utils.h b/modules/assimp/import_utils.h index f4505249db..c522b01727 100644 --- a/modules/assimp/import_utils.h +++ b/modules/assimp/import_utils.h @@ -355,11 +355,13 @@ public: print_verbose("Open Asset Import: Loading embedded texture " + filename); if (tex->mHeight == 0) { if (tex->CheckFormat("png")) { + ERR_FAIL_COND_V(Image::_png_mem_loader_func == NULL, Ref<Image>()); Ref<Image> img = Image::_png_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); ERR_FAIL_COND_V(img.is_null(), Ref<Image>()); state.path_to_image_cache.insert(p_path, img); return img; } else if (tex->CheckFormat("jpg")) { + ERR_FAIL_COND_V(Image::_jpg_mem_loader_func == NULL, Ref<Image>()); Ref<Image> img = Image::_jpg_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); ERR_FAIL_COND_V(img.is_null(), Ref<Image>()); state.path_to_image_cache.insert(p_path, img); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 8abf2ee7ca..8030837cd4 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -915,14 +915,43 @@ GDScript::GDScript() : #endif } +void GDScript::_save_orphaned_subclasses() { + struct ClassRefWithName { + ObjectID id; + String fully_qualified_name; + }; + Vector<ClassRefWithName> weak_subclasses; + // collect subclasses ObjectID and name + 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 + ClassRefWithName subclass; + subclass.id = E->get()->get_instance_id(); + subclass.fully_qualified_name = E->get()->fully_qualified_name; + weak_subclasses.push_back(subclass); + } + + // clear subclasses to allow unused subclasses to be deleted + subclasses.clear(); + // subclasses are also held by constants, clear those as well + constants.clear(); + + // keep orphan subclass only for subclasses that are still in use + for (int i = 0; i < weak_subclasses.size(); i++) { + ClassRefWithName subclass = weak_subclasses[i]; + Object *obj = ObjectDB::get_instance(subclass.id); + if (!obj) + continue; + // subclass is not released + GDScriptLanguage::get_singleton()->add_orphan_subclass(subclass.fully_qualified_name, subclass.id); + } +} + GDScript::~GDScript() { for (Map<StringName, GDScriptFunction *>::Element *E = member_functions.front(); E; E = E->next()) { 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 - } + _save_orphaned_subclasses(); #ifdef DEBUG_ENABLED if (GDScriptLanguage::get_singleton()->lock) { @@ -2176,6 +2205,22 @@ GDScriptLanguage::~GDScriptLanguage() { singleton = NULL; } +void GDScriptLanguage::add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass) { + orphan_subclasses[p_qualified_name] = p_subclass; +} + +Ref<GDScript> GDScriptLanguage::get_orphan_subclass(const String &p_qualified_name) { + Map<String, ObjectID>::Element *orphan_subclass_element = orphan_subclasses.find(p_qualified_name); + if (!orphan_subclass_element) + return Ref<GDScript>(); + ObjectID orphan_subclass = orphan_subclass_element->get(); + Object *obj = ObjectDB::get_instance(orphan_subclass); + orphan_subclasses.erase(orphan_subclass_element); + if (!obj) + return Ref<GDScript>(); + return Ref<GDScript>(Object::cast_to<GDScript>(obj)); +} + /*************** RESOURCE ***************/ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error) { diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 0e2b812a22..4ae52238ce 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -132,6 +132,8 @@ class GDScript : public Script { bool _update_exports(); + void _save_orphaned_subclasses(); + protected: bool _get(const StringName &p_name, Variant &r_ret) const; bool _set(const StringName &p_name, const Variant &p_value); @@ -355,6 +357,8 @@ class GDScriptLanguage : public ScriptLanguage { bool profiling; uint64_t script_frame_time; + Map<String, ObjectID> orphan_subclasses; + public: int calls; @@ -506,6 +510,9 @@ public: virtual bool handles_global_class_type(const String &p_type) const; virtual String get_global_class_name(const String &p_path, String *r_base_type = NULL, String *r_icon_path = NULL) const; + void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass); + Ref<GDScript> get_orphan_subclass(const String &p_qualified_name); + GDScriptLanguage(); ~GDScriptLanguage(); }; diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 711fa54d0b..fba1b992ec 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -2123,15 +2123,21 @@ void GDScriptCompiler::_make_scripts(GDScript *p_script, const GDScriptParser::C StringName name = p_class->subclasses[i]->name; Ref<GDScript> subclass; + String fully_qualified_name = p_script->fully_qualified_name + "::" + name; if (old_subclasses.has(name)) { subclass = old_subclasses[name]; } else { - subclass.instance(); + Ref<GDScript> orphan_subclass = GDScriptLanguage::get_singleton()->get_orphan_subclass(fully_qualified_name); + if (orphan_subclass.is_valid()) { + subclass = orphan_subclass; + } else { + subclass.instance(); + } } subclass->_owner = p_script; - subclass->fully_qualified_name = p_script->fully_qualified_name + "::" + name; + subclass->fully_qualified_name = fully_qualified_name; p_script->subclasses.insert(name, subclass); _make_scripts(subclass.ptr(), p_class->subclasses[i], false); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index e2f2b7fc3b..18dfa49b97 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -555,7 +555,7 @@ static String _get_visual_datatype(const PropertyInfo &p_info, bool p_isarg = tr } if (p_info.type == Variant::NIL) { if (p_isarg || (p_info.usage & PROPERTY_USAGE_NIL_IS_VARIANT)) { - return "var"; + return "Variant"; } else { return "void"; } @@ -1736,14 +1736,12 @@ static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx) { for (const List<PropertyInfo>::Element *E = p_info.arguments.front(); E; E = E->next()) { if (i > 0) { arghint += ", "; - } else { - arghint += " "; } if (i == p_arg_idx) { arghint += String::chr(0xFFFF); } - arghint += _get_visual_datatype(E->get(), true) + " " + E->get().name; + arghint += E->get().name + ": " + _get_visual_datatype(E->get(), true); if (i - def_args >= 0) { arghint += String(" = ") + p_info.default_arguments[i - def_args].get_construct_string(); @@ -1759,8 +1757,6 @@ static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx) { if (p_info.flags & METHOD_FLAG_VARARG) { if (p_info.arguments.size() > 0) { arghint += ", "; - } else { - arghint += " "; } if (p_arg_idx >= p_info.arguments.size()) { arghint += String::chr(0xFFFF); @@ -1770,9 +1766,6 @@ static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx) { arghint += String::chr(0xFFFF); } } - if (p_info.arguments.size() > 0 || (p_info.flags & METHOD_FLAG_VARARG)) { - arghint += " "; - } arghint += ")"; @@ -1787,14 +1780,12 @@ static String _make_arguments_hint(const GDScriptParser::FunctionNode *p_functio for (int i = 0; i < p_function->arguments.size(); i++) { if (i > 0) { arghint += ", "; - } else { - arghint += " "; } if (i == p_arg_idx) { arghint += String::chr(0xFFFF); } - arghint += p_function->argument_types[i].to_string() + " " + p_function->arguments[i].operator String(); + arghint += p_function->arguments[i].operator String() + ": " + p_function->argument_types[i].to_string(); if (i - def_args >= 0) { String def_val = "<unknown>"; @@ -1818,9 +1809,6 @@ static String _make_arguments_hint(const GDScriptParser::FunctionNode *p_functio } } - if (p_function->arguments.size() > 0) { - arghint += " "; - } arghint += ")"; return arghint; diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 236ca720a2..ad95ebc543 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -76,14 +76,17 @@ struct GDScriptDataType { if (p_variant.get_type() != Variant::OBJECT) { return false; } + Object *obj = p_variant.operator Object *(); - if (obj) { - if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) { - // Try with underscore prefix - StringName underscore_native_type = "_" + native_type; - if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) { - return false; - } + if (!obj || !ObjectDB::instance_validate(obj)) { + return false; + } + + if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) { + // Try with underscore prefix + StringName underscore_native_type = "_" + native_type; + if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) { + return false; } } return true; @@ -96,7 +99,12 @@ struct GDScriptDataType { if (p_variant.get_type() != Variant::OBJECT) { return false; } + Object *obj = p_variant.operator Object *(); + if (!obj || !ObjectDB::instance_validate(obj)) { + return false; + } + Ref<Script> base = obj && obj->get_script_instance() ? obj->get_script_instance()->get_script() : NULL; bool valid = false; while (base.is_valid()) { diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index fc2e626795..5c2e7137bf 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4741,10 +4741,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { member.line = tokenizer->get_token_line(); member.usages = 0; member.rpc_mode = rpc_mode; -#ifdef TOOLS_ENABLED - Variant::CallError ce; - member.default_value = Variant::construct(member._export.type, NULL, 0, ce); -#endif if (current_class->constant_expressions.has(member.identifier)) { _set_error("A constant named \"" + String(member.identifier) + "\" already exists in this class (at line: " + @@ -4797,6 +4793,32 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } } + if (autoexport && member.data_type.has_type) { + if (member.data_type.kind == DataType::BUILTIN) { + member._export.type = member.data_type.builtin_type; + } else if (member.data_type.kind == DataType::NATIVE) { + if (ClassDB::is_parent_class(member.data_type.native_type, "Resource")) { + member._export.type = Variant::OBJECT; + member._export.hint = PROPERTY_HINT_RESOURCE_TYPE; + member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; + member._export.hint_string = member.data_type.native_type; + member._export.class_name = member.data_type.native_type; + } else { + _set_error("Invalid export type. Only built-in and native resource types can be exported.", member.line); + return; + } + + } else { + _set_error("Invalid export type. Only built-in and native resource types can be exported.", member.line); + return; + } + } + +#ifdef TOOLS_ENABLED + Variant::CallError ce; + member.default_value = Variant::construct(member._export.type, NULL, 0, ce); +#endif + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { #ifdef DEBUG_ENABLED @@ -4930,27 +4952,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { member.initial_assignment = op; } - if (autoexport && member.data_type.has_type) { - if (member.data_type.kind == DataType::BUILTIN) { - member._export.type = member.data_type.builtin_type; - } else if (member.data_type.kind == DataType::NATIVE) { - if (ClassDB::is_parent_class(member.data_type.native_type, "Resource")) { - member._export.type = Variant::OBJECT; - member._export.hint = PROPERTY_HINT_RESOURCE_TYPE; - member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; - member._export.hint_string = member.data_type.native_type; - member._export.class_name = member.data_type.native_type; - } else { - _set_error("Invalid export type. Only built-in and native resource types can be exported.", member.line); - return; - } - - } else { - _set_error("Invalid export type. Only built-in and native resource types can be exported.", member.line); - return; - } - } - if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_SETGET) { tokenizer->advance(); diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index c68404fdf5..0f6b8357b8 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -2176,6 +2176,17 @@ CSharpInstance::~CSharpInstance() { // Transfer ownership to an "instance binding" + Reference *ref_owner = static_cast<Reference *>(owner); + + // We will unreference the owner before referencing it again, so we need to keep it alive + Ref<Reference> scope_keep_owner_alive(ref_owner); + (void)scope_keep_owner_alive; + + // Unreference the owner here, before the new "instance binding" references it. + // Otherwise, the unsafe reference debug checks will incorrectly detect a bug. + bool die = _unreference_owner_unsafe(); + CRASH_COND(die == true); // `owner_keep_alive` holds a reference, so it can't die + void *data = owner->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); CRASH_COND(data == NULL); @@ -2191,8 +2202,10 @@ CSharpInstance::~CSharpInstance() { } } - bool die = _unreference_owner_unsafe(); - CRASH_COND(die == true); // The "instance binding" should be holding a reference +#ifdef DEBUG_ENABLED + // The "instance binding" holds a reference so the refcount should be at least 2 before `scope_keep_owner_alive` goes out of scope + CRASH_COND(ref_owner->reference_get_count() <= 1); +#endif } if (script.is_valid() && owner) { diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml index cd47c10f80..2074a10fa9 100644 --- a/modules/websocket/doc_classes/WebSocketServer.xml +++ b/modules/websocket/doc_classes/WebSocketServer.xml @@ -83,7 +83,7 @@ </method> </methods> <members> - <member name="bind_ip" type="String" setter="set_bind_ip" getter="get_bind_ip"> + <member name="bind_ip" type="String" setter="set_bind_ip" getter="get_bind_ip" default=""*""> When not set to [code]*[/code] will restrict incoming connections to the specified IP address. Setting [code]bind_ip[/code] to [code]127.0.0.1[/code] will cause the server to listen only to the local host. </member> <member name="ca_chain" type="X509Certificate" setter="set_ca_chain" getter="get_ca_chain"> |