Repository navigation
fix: Texture2D without image data and streamed Texture2DArray - #391
Open
nichinichisou0609 wants to merge 2 commits into
Open
nichinichisou0609 wants to merge 2 commits into
nichinichisou0609 wants to merge 2 commits into
Conversation
A dynamic font keeps its glyph texture in a Texture2D named "Font Texture" with a width and height of 0 and no image data. Like every texture that is not streamed, it serializes m_StreamData with an empty path, offset 0 and size 0. Texture2D.get_image_data looked up a resource whenever m_StreamData was set, so reading the image of such a texture passed an empty name to get_resource_data, which opened the environment directory as a file and failed with PermissionError on Windows and IsADirectoryError on Linux. A texture with a size and no image data took the same path. get_image_from_texture2d now returns an empty image for a texture without width or height, as parse_image_data does, without fetching any data. get_image_data reads a resource only when m_StreamData names one, and raises "No image data found" otherwise. tests/test_texture.py builds both textures in memory and checks that no dependency is loaded.
Texture2DArray.images only read m_StreamData when image_data was None. A streamed array serializes image_data as an empty byte string, so the resource file was never read and every streamed array failed with "Texture2D has no image data". Texture2DArray now has get_image_data(), with the same rules as Texture2D.get_image_data(): the inline data when there is any, else the resource named by m_StreamData, else a ValueError. images uses it and decodes the layers with the platform of the object reader instead of platform 0, as Texture2D does. tests/test_texture.py decodes a two-layer RGBA32 array stored inline and the same array stored in a registered .resS resource.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two fixes for reading texture data; one commit each, and each commit adds a regression test that fails on its parent and passes with the fix.
Texture2Dnamed "Font Texture" with a width and height of 0 and no image data. Like every texture that is not streamed, it serializesm_StreamDatawith an empty path, offset 0 and size 0.Texture2D.get_image_datalooked up a resource wheneverm_StreamDatawas set, so reading.imageof such a texture passed an empty name toget_resource_data, which opened the environment directory as a file and failed withPermissionErroron Windows andIsADirectoryErroron Linux. A texture with a size and no image data took the same path.get_image_from_texture2dnow returns an empty image for a texture without width or height, asparse_image_dataalready does, without fetching any data, andget_image_datareads a resource only whenm_StreamData.pathnames one and raisesValueError("No image data found")otherwise.Texture2DArray.imagesreadm_StreamDataonly whenimage_datawasNone. A streamed array serializesimage_dataas an empty byte string, so every streamed array failed withTexture2D has no image data.Texture2DArraynow hasget_image_data()with the same rules asTexture2D.get_image_data(), andimagesdecodes the layers with the platform of the object reader instead of platform 0, asTexture2Ddoes.tests/test_texture.py(new) builds the objects in memory: a 0x0 texture and a 2x2 texture without data, both without loading any dependency, and a two-layer RGBA32 array stored inline, stored in a.resSregistered withEnvironment.register_cab, and without data. The inline array passes before the change as well and is there as a baseline.Validation on Windows x86_64, CPython 3.11.13, pytest 9.1.1, Pillow 12.3.0. The compiled path uses the
UnityPyBoostextension of the 1.25.4 wheel;UnityPyBoost/has no changes between 1.25.4 and417d595. A "Font Texture" from a player build made with Unity 6000.3 raisedPermissionErrorbefore the change and returns a 0x0 image after it.417d595ruff checkandruff format --check