Fix #3104: include file-referenced assets in MjSpec.to_zip#3372
Open
Ashutosh0x wants to merge 1 commit into
Open
Fix #3104: include file-referenced assets in MjSpec.to_zip#3372Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit into
Conversation
…_zip to_zip only serialized assets present in spec.assets (the Python-side dict). Assets referenced via XML file paths, e.g. <mesh file=cube.obj/>, were loaded by the C layer but never added to spec.assets, so they were silently omitted from the zip, making it unloadable. Fix: walk all spec elements that can carry file references (meshes, hfields, skins, textures including cubefiles) and read each referenced file from disk when it is not already in spec.assets. Also fix two secondary bugs: spec.assets was mutated in-place (now copied first), and os.makedirs was called with an empty string when saving to the current directory (now guarded). Fixes google-deepmind#3104
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.
Problem
MjSpec.to_ziponly serializes assets present in the Python-sidespec.assetsdict. Assets referenced via XML file attributes — e.g.<mesh file="cube.obj"/>,<texture file="tex.png"/>— are loaded by the C layer from disk but are never added tospec.assets, so they are silently omitted from the zip. The resulting zip cannot be reloaded.Fixes #3104.
Changes
python/mujoco/__init__.pyspec.assets, walk all spec elements that can carryfilereferences:meshes,hfields,skins, andtextures(includingcubefiles).spec.modelfiledirand read it from disk. Files not found on disk are silently skipped (in-memory assets already inspec.assetstake precedence).spec.assetswas mutated in-place (files_to_zip = spec.assetsthen items were added to it); now a copy is made first so the caller's dict is untouched.os.makedirs(directory, ...)was called even whendirectoryis''(e.g. saving to current directory), which raisesFileNotFoundError; now guarded withif directory.python/mujoco/specs_test.pytest_to_zip_includes_file_assets: loadstestdata/msh.xml(which referencesabdomen_1_body.mshby file path), callsto_zip, and asserts the mesh file is present in the zip. Also verifies the zip round-trips to a compilable spec.test_to_zip_does_not_mutate_assets: assertsspec.assetscontent is unchanged afterto_zip.Reproducer