Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix to allow TextureArrays to be serialized #70212

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

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

@@ -2703,7 +2703,7 @@ void TextureLayered::_bind_methods() {
ClassDB::bind_method(D_METHOD("_get_data"), &TextureLayered::_get_data);

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.

@lawnjelly lawnjelly modified the milestones: 3.6, 3.7 Sep 11, 2024
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.

5 participants