Skip to content

Fix #2492: normalize image path before existence check#2710

Open
Builder106 wants to merge 1 commit into
KhronosGroup:mainfrom
Builder106:fix/2492-image-path-normalize
Open

Fix #2492: normalize image path before existence check#2710
Builder106 wants to merge 1 commit into
KhronosGroup:mainfrom
Builder106:fix/2492-image-path-normalize

Conversation

@Builder106

Copy link
Copy Markdown

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 returns None and the image is excluded from the export.

Fix

Normalize the path with os.path.normpath() before the existence check:

path_to_image = os.path.normpath(bpy.path.abspath(original_uri, library=library))

normpath() collapses the redundant .. / separator segments, which both resolves the failed exists() check and shortens the over-long paths described in the thread. I used normpath rather than the os.path.realpath mentioned in the issue because it fixes the same cases without resolving symlinks — that keeps the subsequent os.path.relpath(..., start=export_settings['gltf_filedirectory']) predictable for users whose asset folders are symlinked. Happy to switch to realpath if you'd prefer.

Verification

Repro: a texture referenced via //ghost/../real.png (where ghost/ does not exist), exported as glTF-Separate with Keep original textures enabled.

  • Before: export produced "images": [] — the texture was lost.
  • After: the texture is exported correctly with "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.

@CLAassistant

CLAassistant commented Jun 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Builder106

Copy link
Copy Markdown
Author

Hey @julienduroure, checking in on this one, it's been about three weeks without a review. The fix is small, one line: os.path.normpath() before the existence check in __gather_original_uri, since bpy.path.abspath() can return an absolute path that still has unresolved .. segments in it. I included a before and after repro in the description (images: [] versus the texture actually surviving export) if that's a faster way to confirm the behavior than tracing the diff cold. Happy to add a test fixture too if that would help review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong absolute path of images

2 participants