Skip to content

Conversation

@Ithamar
Copy link

@Ithamar Ithamar commented Dec 17, 2022

This fixes serialisation of TextureArray based classes. For a long time (at least since 3.2) this has been broken, writing nulls as layer images in the resulting resource files.

This is targeting 3.x since serialisation is completely missing from the master branch, and code has diverged so much that there is no obvious way to fix it for both codebases in one go.

This will fix #54202, #38870, #34312 and many others.

NOTE: this commit was taken from V-Sekai@2ba3561, authored by @SaracenOne that I was made aware of by @Calinou in issue #54202

Tested using the following snippet:

	var i := Image.new()
        i.create(1, 1, false, Image.FORMAT_RGB8)
	i.lock()
	i.set_pixel(0,0, Color(1,0,0))
	i.unlock()
	ResourceSaver.save("res://image.tres", i)
	var l := TextureArray.new()
	l.create(1, 1, 1, Image.FORMAT_RGB8)
	l.set_layer_data(i, 1)
	ResourceSaver.save("res://layered.tres", l)

and checking the layered.tres for non-null layer data.

@Ithamar Ithamar requested a review from a team as a code owner December 17, 2022 19:45
@akien-mga akien-mga added this to the 3.6 milestone Dec 17, 2022
@fire fire requested a review from SaracenOne December 17, 2022 21:30
@akien-mga akien-mga changed the title Fix to allow TextureArrays to be serialised [3.x] [3.x] Fix to allow TextureArrays to be serialised Jun 19, 2023
@YuriSizov YuriSizov changed the title [3.x] Fix to allow TextureArrays to be serialised [3.x] Fix to allow TextureArrays to be serialized Jul 28, 2023
Copy link
Member

@SaracenOne SaracenOne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about this. So yeah, for people still on 3.x, we might as well merge this I think


ADD_PROPERTY(PropertyInfo(Variant::INT, "flags", PROPERTY_HINT_FLAGS, "Mipmaps,Repeat,Filter,Anisotropic Filter"), "set_flags", "get_flags");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_data", "_get_data");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT), "_set_data", "_get_data");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the right solution? RESOURCE_NOT_PERSISTENT seems like it's intended for resources, and here it's a dictionary. Indeed, the serialization code had to be changed to handle this dictionary.

Wouldn't this work with PROPERTY_USAGE_INTERNAL?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closest equivalent on master (_images of ImageTextureLayered) uses PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT. It's an Array of Images instead of Dictionary like here, but it doesn't make much difference. The serialization code changes match master.

@lawnjelly lawnjelly modified the milestones: 3.6, 3.7 Sep 11, 2024
@aaronfranke aaronfranke requested review from KoBeWi and lawnjelly July 26, 2025 03:29
@lawnjelly
Copy link
Member

Just to note I'm aware of the PR (as it was bumped), but it is waiting for Akien's points to be addressed.

It may be the original author has abandoned as the PR is 3 years old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants