JuliaGeometry / OldMeshes.jl

A collection of tools for working with Meshes
Other
20 stars 12 forks source link

Invalid UTF-8 character index error when importing binary stl #56

Closed dreammaker closed 9 years ago

dreammaker commented 9 years ago

We are currently misidentifying binary stl format as ascii stl, which is causing this error. SolidWorks, in particular, exports binary stl files with the string "solid" in the header. Since the 80-byte header can be anything in the binary format, it shouldn't be used to determine the format.

This is the backtrace I'm seeing.

ERROR: invalid UTF-8 character index
 in next at ./utf8.jl:69
 in map at string.jl:820
 in lowercase at string.jl:803
 in importAsciiSTL at /home/julia/.julia/v0.3/Meshes/src/files/stl.jl:141
 in mesh at /home/julia/.julia/v0.3/Meshes/src/Files.jl:57
sjkelly commented 9 years ago

Can you attach the file in question? Maybe MeshesIO will help?

cc @SimonDanisch

sjkelly commented 9 years ago

FWIW this is how Cura disambiguates: https://github.com/Ultimaker/CuraEngine/blob/160612f0dc09f3084d7d7aec6b6147e5f391af7b/src/MeshGroup.cpp#L105-L136

SimonDanisch commented 9 years ago

This is solved in MeshIO + FileIO: https://github.com/JuliaIO/FileIO.jl/blob/sd/improvements/src/registry.jl#L153

Hope we can publish this soon!

dreammaker commented 9 years ago

Without actually running it, it looks like both of the above links to Cura and MeshIO have this bug also. They both check for the string "solid" and if found, assume the file is ascii. This will fail. From what I can tell, SolidWorks is treating the header as a comment.

See Blender's source for a version that would work.

I'll see if I can get an example export that I can upload.

SimonDanisch commented 9 years ago

that's actually not true for detect_stlbinary... If it detects "solid ", it knows its not binary... ;) the detection of ascii is independant of this (though probably not correct).

SimonDanisch commented 9 years ago

Hm, yeah but you're still right, that this might fail. I can remove that line!

SimonDanisch commented 9 years ago

So, any pull requests are welcome to improve the detection ;)

dreammaker commented 9 years ago

GitHub doesn't seem to allow arbitrary files in comments. I made a branch with an example file and a failing test. I'll make a patch and pull request when I have time. I think the issue should be open in the meantime.

SimonDanisch commented 9 years ago

Nice, thank you =) Would you mind creating the PR in MeshIO though? IO in Meshes.jl should be deprecated soon.

SimonDanisch commented 9 years ago

Okay I included it into FileIO and MeshIO :D

dreammaker commented 9 years ago

Nice, @SimonDanisch! That was quick!

I'm probably going to still backport your fix here to Meshes.jl.

sjkelly commented 9 years ago

Should be fixed in the 0.1.x branch