Road-hog123 / Blender-OMSI-Exporter

OMSI Mesh (.o3d) exporter addon for Blender and Blender LTS
Apache License 2.0
24 stars 0 forks source link

Uncaught error if texture path exceeds 255 characters #13

Open Road-hog123 opened 1 year ago

Road-hog123 commented 1 year ago

Within an OMSI mesh file strings are limited to 255 characters—this applies both to texture paths and bone names. Vertex group names are limited to 63 characters, so bone names are not an issue; however Blender permits image filepaths to be up to 1023 characters, which makes it possible to enter a filepath that has more than 255 characters after the last texture folder.

Fortunately attempting to encode a string longer than 255 characters results in a Python exception instead of writing a corrupt mesh file, however it would be better to catch the exception and report a useful error message.

Traceback (most recent call last):
  File "io_export_o3d\__init__.py", line 218, in execute
    exporter.export(objects, Path(self.filepath))
  File "io_export_o3d\exporter.py", line 322, in export
    b = meshio.dump(mesh, self._fs)
  File "io_export_o3d\meshio.py", line 437, in dump
    ba += es(m.texture)
  File "io_export_o3d\meshio.py", line 382, in es
    return ef(fs._stringLengthFormat, len(s)) + s.encode(fs._stringFormat)
  File "io_export_o3d\meshio.py", line 378, in ef
    return pack('<' + fmt.fmt, *v)
struct.error: ubyte format requires 0 <= number <= 255