Skip to content

Fix asset paths in from_zip on Windows - #569

Draft
rootkiller6788 wants to merge 1 commit into
google-deepmind:mainfrom
rootkiller6788:fix-zip-asset-separators
Draft

rootkiller6788 wants to merge 1 commit into
google-deepmind:mainfrom
rootkiller6788:fix-zip-asset-separators

Conversation

@rootkiller6788

Copy link
Copy Markdown

Small fix for loading zipped MJCF models on Windows. In from_zip the asset keys are built with os.path.relpath(name, model_dir), which gives backslash-separated paths on Windows, but zip entries and the paths referenced from MJCF XML always use '/'. So any model with assets in a subfolder gets asset keys like 'meshes\cube.stl' that never match the 'meshes/cube.stl' references in the model, and the load fails. Directory entries also slip through because they end in '/' in a zip, not os.path.sep.

Verified on Windows against the bundled model_with_assetdir.zip: before the change keys come out as 'meshes\cube.stl' / 'textures\deepmind.png' plus empty-byte keys for the 'meshes/' and 'textures/' entries; after it the keys are 'meshes/cube.stl' and 'textures/deepmind.png' and the directory entries are skipped. On Linux/macOS this is a no-op (replace is a no-op and endswith('/') already matched os.path.sep), so existing behaviour and tests are unchanged.

os.path.relpath returns backslash-separated paths on Windows, but zip
entries and the file= attributes in MJCF XML always use '/'. As a
result models with assets in subfolders could not be loaded from a zip
on Windows, and directory entries (which end in '/' in a zip) were not
being filtered out because os.path.sep is '\' there.

Normalise the relpath result to '/', and check for '/' when skipping
directory entries.
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.

1 participant