Skip to content

Commit

Permalink
Merge pull request #71394 from Ithamar/feat-imagetexlay-ser
Browse files Browse the repository at this point in the history
Fix ImageTextureLayered serialisation issues
  • Loading branch information
YuriSizov committed Jul 24, 2023
2 parents 91258e5 + f37c2b5 commit d6bb6d4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
11 changes: 7 additions & 4 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1970,14 +1970,17 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
if (E.usage & PROPERTY_USAGE_STORAGE) {
Variant value = res->get(E.name);
if (E.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) {
NonPersistentKey npk;
npk.base = res;
npk.property = E.name;
non_persistent_map[npk] = value;

Ref<Resource> sres = value;
if (sres.is_valid()) {
NonPersistentKey npk;
npk.base = res;
npk.property = E.name;
non_persistent_map[npk] = sres;
resource_set.insert(sres);
saved_resources.push_back(sres);
} else {
_find_resources(value);
}
} else {
_find_resources(value);
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_format_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ResourceFormatSaverBinaryInstance {
bool operator<(const NonPersistentKey &p_key) const { return base == p_key.base ? property < p_key.property : base < p_key.base; }
};

RBMap<NonPersistentKey, Ref<Resource>> non_persistent_map;
RBMap<NonPersistentKey, Variant> non_persistent_map;
HashMap<StringName, int> string_map;
Vector<StringName> strings;

Expand Down
2 changes: 1 addition & 1 deletion scene/resources/image_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void ImageTextureLayered::_bind_methods() {
ClassDB::bind_method(D_METHOD("_get_images"), &ImageTextureLayered::_get_images);
ClassDB::bind_method(D_METHOD("_set_images", "images"), &ImageTextureLayered::_set_images);

ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_images", PROPERTY_HINT_ARRAY_TYPE, "Image", PROPERTY_USAGE_INTERNAL), "_set_images", "_get_images");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_images", PROPERTY_HINT_ARRAY_TYPE, "Image", PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT), "_set_images", "_get_images");
}

ImageTextureLayered::ImageTextureLayered(LayeredType p_layered_type) {
Expand Down
11 changes: 7 additions & 4 deletions scene/resources/resource_format_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1893,14 +1893,17 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
Variant v = res->get(I->get().name);

if (pi.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) {
NonPersistentKey npk;
npk.base = res;
npk.property = pi.name;
non_persistent_map[npk] = v;

Ref<Resource> sres = v;
if (sres.is_valid()) {
NonPersistentKey npk;
npk.base = res;
npk.property = pi.name;
non_persistent_map[npk] = sres;
resource_set.insert(sres);
saved_resources.push_back(sres);
} else {
_find_resources(v);
}
} else {
_find_resources(v);
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/resource_format_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class ResourceFormatSaverTextInstance {
bool operator<(const NonPersistentKey &p_key) const { return base == p_key.base ? property < p_key.property : base < p_key.base; }
};

RBMap<NonPersistentKey, Ref<Resource>> non_persistent_map;
RBMap<NonPersistentKey, Variant> non_persistent_map;

HashSet<Ref<Resource>> resource_set;
List<Ref<Resource>> saved_resources;
Expand Down

0 comments on commit d6bb6d4

Please sign in to comment.