Fix #2492: normalize image path before existence check#2710
Open
Builder106 wants to merge 1 commit into
Open
Conversation
Author
|
Hey @julienduroure, checking in on this one, it's been about three weeks without a review. The fix is small, one line: |
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.
Fixes #2492.
Bug
With Keep original textures enabled, a texture whose resolved path contains relative segments (a
..passing through a directory that doesn't exist) — or that is long because of such redundant segments — is silently dropped from the export.Root cause
In
__gather_original_uri(addons/io_scene_gltf2/blender/exp/material/image.py),bpy.path.abspath()can return an absolute path that still contains..segments.os.path.exists()then fails on that path (an intermediate component can't be traversed), so the function returnsNoneand the image is excluded from the export.Fix
Normalize the path with
os.path.normpath()before the existence check:normpath()collapses the redundant../ separator segments, which both resolves the failedexists()check and shortens the over-long paths described in the thread. I usednormpathrather than theos.path.realpathmentioned in the issue because it fixes the same cases without resolving symlinks — that keeps the subsequentos.path.relpath(..., start=export_settings['gltf_filedirectory'])predictable for users whose asset folders are symlinked. Happy to switch torealpathif you'd prefer.Verification
Repro: a texture referenced via
//ghost/../real.png(whereghost/does not exist), exported as glTF-Separate with Keep original textures enabled."images": []— the texture was lost."uri": "../real.png".A standalone repro script (builds the scene, exports, and asserts the image survives) is available — glad to attach it or adapt it into a roundtrip fixture if that's preferred.