diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/io/resource.cpp | 19 | ||||
| -rw-r--r-- | core/io/resource.h | 2 | ||||
| -rw-r--r-- | core/io/stream_peer_gzip.cpp | 1 |
3 files changed, 19 insertions, 3 deletions
diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 7e8d0b43cd..5edb045760 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -130,6 +130,16 @@ String Resource::generate_scene_unique_id() { } void Resource::set_scene_unique_id(const String &p_id) { + bool is_valid = true; + for (int i = 0; i < p_id.length(); i++) { + if (!is_ascii_identifier_char(p_id[i])) { + is_valid = false; + scene_unique_id = Resource::generate_scene_unique_id(); + break; + } + } + + ERR_FAIL_COND_MSG(!is_valid, "The scene unique ID must contain only letters, numbers, and underscores."); scene_unique_id = p_id; } @@ -425,7 +435,7 @@ RID Resource::get_rid() const { #ifdef TOOLS_ENABLED -uint32_t Resource::hash_edited_version() const { +uint32_t Resource::hash_edited_version_for_preview() const { uint32_t hash = hash_murmur3_one_32(get_edited_version()); List<PropertyInfo> plist; @@ -435,7 +445,7 @@ uint32_t Resource::hash_edited_version() const { if (E.usage & PROPERTY_USAGE_STORAGE && E.type == Variant::OBJECT && E.hint == PROPERTY_HINT_RESOURCE_TYPE) { Ref<Resource> res = get(E.name); if (res.is_valid()) { - hash = hash_murmur3_one_32(res->hash_edited_version(), hash); + hash = hash_murmur3_one_32(res->hash_edited_version_for_preview(), hash); } } } @@ -532,6 +542,10 @@ void Resource::_bind_methods() { ClassDB::bind_method(D_METHOD("get_local_scene"), &Resource::get_local_scene); ClassDB::bind_method(D_METHOD("setup_local_to_scene"), &Resource::setup_local_to_scene); + ClassDB::bind_static_method("Resource", D_METHOD("generate_scene_unique_id"), &Resource::generate_scene_unique_id); + ClassDB::bind_method(D_METHOD("set_scene_unique_id", "id"), &Resource::set_scene_unique_id); + ClassDB::bind_method(D_METHOD("get_scene_unique_id"), &Resource::get_scene_unique_id); + ClassDB::bind_method(D_METHOD("emit_changed"), &Resource::emit_changed); ClassDB::bind_method(D_METHOD("duplicate", "subresources"), &Resource::duplicate, DEFVAL(false)); @@ -542,6 +556,7 @@ void Resource::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resource_local_to_scene"), "set_local_to_scene", "is_local_to_scene"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_path", "get_path"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_name"), "set_name", "get_name"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_scene_unique_id", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_scene_unique_id", "get_scene_unique_id"); MethodInfo get_rid_bind("_get_rid"); get_rid_bind.return_val.type = Variant::RID; diff --git a/core/io/resource.h b/core/io/resource.h index f0f686af57..cc8a0d4387 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -125,7 +125,7 @@ public: #ifdef TOOLS_ENABLED - uint32_t hash_edited_version() const; + virtual uint32_t hash_edited_version_for_preview() const; virtual void set_last_modified_time(uint64_t p_time) { last_modified_time = p_time; } uint64_t get_last_modified_time() const { return last_modified_time; } diff --git a/core/io/stream_peer_gzip.cpp b/core/io/stream_peer_gzip.cpp index 4daa71a22a..514bcf59b8 100644 --- a/core/io/stream_peer_gzip.cpp +++ b/core/io/stream_peer_gzip.cpp @@ -76,6 +76,7 @@ Error StreamPeerGZIP::start_decompression(bool p_is_deflate, int buffer_size) { Error StreamPeerGZIP::_start(bool p_compress, bool p_is_deflate, int buffer_size) { ERR_FAIL_COND_V(ctx != nullptr, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V_MSG(buffer_size <= 0, ERR_INVALID_PARAMETER, "Invalid buffer size. It should be a positive integer."); clear(); compressing = p_compress; rb.resize(nearest_shift(buffer_size - 1)); |
