jschobben / colorscad

Script to produce colorized OpenSCAD models
Other
43 stars 7 forks source link

Segmentation fault #2

Closed colorscad-tester closed 3 years ago

colorscad-tester commented 3 years ago

Hello,

I am quite interested in your program as it looks like it could save a lot of fiddling going from openscad to a slicer. I would love to get this working.

Compiling 3mfmerge was a pain, I ended up doing:

 wget https://github.com/3MFConsortium/lib3mf/releases/download/v2.1.1/lib3mf_sdk_v2.1.1.zip
mkdir lib3mf_sdk
cd lib3mf_sdk
unzip ../lib3mf_sdk_v2.1.1.zip

Then editing CMakeLists.txt and adding:

set(LIB3MF_LOCATION __Full_Path_To_colorscad__/colorscad/3mfmerge/lib3mf_sdk/Lib/lib3mf.lib)
set(LIB3MF_CPP_BINDINGS_DIR __Full_Path_To_colorscad__/colorscad/3mfmerge/lib3mf_sdk/Bindings/Cpp)

Then I was able to compile 3mfmerge which seemed to work fine. Not sure if there is a better way to feed cmake those variables.

Then I tried to make it work but got a segmentation fault

$ ./colorscad.sh ../blah/blah/label.scad ../blah/blah/label.3mf
Get list of used colors
1 unique colors were found.

Create a separate .3mf file for each color

Generate a merged .3mf file
./colorscad.sh: line 177: 171158 Segmentation fault      "${DIR_3MFMERGE}"/build/3mfmerge merged.3mf < <(echo "$COLORS" | sed "s/\$/\.${INTERMEDIATE}/")
mv: cannot stat '/tmp/tmp.I31iJnusjc/merged.3mf': No such file or directory

../openscad/plant_labels/label.3mf created, but there were some problems (merge step exit status: 139).

Interestingly it seems to get further if I copy the file to the dir with colorscad

$ ./colorscad.sh label.scad  label.3mf
Get list of used colors
3 unique colors were found.

Create a separate .3mf file for each color
./colorscad.sh: line 118: wait: 1: no such job
./colorscad.sh: line 118: wait: 1: no such job
./colorscad.sh: line 118: wait: 1: no such job
Jobs completed: 3/3 

Generate a merged .3mf file
./colorscad.sh: line 177: 171103 Segmentation fault      "${DIR_3MFMERGE}"/build/3mfmerge merged.3mf < <(echo "$COLORS" | sed "s/\$/\.${INTERMEDIATE}/")
mv: cannot stat '/tmp/tmp.wunnti3p8s/merged.3mf': No such file or directory

label.3mf created, but there were some problems (merge step exit status: 139).

I made a really really simple test file

$ cat simpletest.scad 
color("red") cube([5,5,5]);

color("white") cube([8,8,3]);

It does the same thing

$ ./colorscad.sh simpletest.scad simpletest.3mf
Get list of used colors
2 unique colors were found.

Create a separate .3mf file for each color
./colorscad.sh: line 118: wait: 1: no such job
./colorscad.sh: line 118: wait: 1: no such job
Jobs completed: 2/2 

Generate a merged .3mf file
./colorscad.sh: line 177: 172301 Segmentation fault      "${DIR_3MFMERGE}"/build/3mfmerge merged.3mf < <(echo "$COLORS" | sed "s/\$/\.${INTERMEDIATE}/")
mv: cannot stat '/tmp/tmp.ZY4JbgDw6k/merged.3mf': No such file or directory

simpletest.3mf created, but there were some problems (merge step exit status: 139).
terminal_prompt$ 1/2 [1, 1, 1, 1] Can't open input file './tmp.U1LuerLiqC.csg'!
1/2 [1, 1, 1, 1] 
2/2 [1, 0, 0, 1] Can't open input file './tmp.U1LuerLiqC.csg'!
2/2 [1, 0, 0, 1] 
2/2 [1, 0, 0, 1] Warning: output is empty!
1/2 [1, 1, 1, 1] Warning: output is empty!

Despite saying it created one no output file exists.

I think 3mfmerge is my issue, it sounds like it should run if and take input if I just give it an arg for an output file?

$ ./3mfmerge merged.3mf
Segmentation fault
jschobben commented 3 years ago

What 3mfmerge needs, is a proper build system 😅. Let me see in the evening if I can come up with something nice.

Just guessing here, but maybe the issue is an API mismatch with the latest lib3mf version. Does an older one work? Maybe there's some useful info in a stacktrace for the segfault.

colorscad-tester commented 3 years ago

Thanks for your reply

Tried catchsegv but it did not give me a backtrace, just the register dump

$ catchsegv ./3mfmerge merged.3mf
Segmentation fault
*** Segmentation fault
Register dump:

 RAX: 00007fff82ab4ac0   RBX: 0000000000000000   RCX: 00007fff82ab49de
 RDX: 0000556b69120ef0   RSI: 0000556b69120ef0   RDI: 00007fff82ab4ac0
 RBP: 00007fff82ab4ad0   R8 : 0000556b69120ee0   R9 : 00007f959a46fbe0
 R10: fffffffffffffcf5   R11: 0000000000000020   R12: 0000556b6819d310
 R13: 0000000000000000   R14: 0000000000000000   R15: 0000000000000000
 RSP: 00007fff82ab4aa8

 RIP: 000000000001d628   EFLAGS: 00010202

 CS: 0033   FS: 0000   GS: 0000

 Trap: 0000000e   Error: 00000014   OldMask: 00000000   CR2: 0001d628

 FPUCW: 0000037f   FPUSW: 00000000   TAG: 00000000
 RIP: 00000000   RDP: 00000000

 ST(0) 0000 0000000000000000   ST(1) 0000 0000000000000000
 ST(2) 0000 0000000000000000   ST(3) 0000 0000000000000000
 ST(4) 0000 0000000000000000   ST(5) 0000 0000000000000000
 ST(6) 0000 0000000000000000   ST(7) 0000 0000000000000000
 mxcsr: 1f80
 XMM0:  000000000000000000000000ffffffff XMM1:  000000000000000000000000ffffffff
 XMM2:  000000000000000000000000ffffffff XMM3:  000000000000000000000000ffffffff
 XMM4:  000000000000000000000000ffffffff XMM5:  000000000000000000000000ffffffff
 XMM6:  000000000000000000000000ffffffff XMM7:  000000000000000000000000ffffffff
 XMM8:  000000000000000000000000ffffffff XMM9:  000000000000000000000000ffffffff
 XMM10: 000000000000000000000000ffffffff XMM11: 000000000000000000000000ffffffff
 XMM12: 000000000000000000000000ffffffff XMM13: 000000000000000000000000ffffffff
 XMM14: 000000000000000000000000ffffffff XMM15: 000000000000000000000000ffffffff

Backtrace:

I can try downgrading lib3mf too, any specific version that's known to work?

jschobben commented 3 years ago

Hmm, of course 3mfmerge isn't configured as a debug build, so there'd be no useful info in the stacktrace indeed.

But the "good" news is, I can easily reproduce this when using the lib3mf_sdk binaries on Ubuntu 18.04: looks like the segfault occurs inside the lib3mf binary itself (both with 2.0.0 which was the latest "known to work" version, and with 2.1.1).

What's really good news though, is that it works fine when lib3mf is built from source (both 2.0.0 and 2.1.1), so that's probably the best solution in general. I guess the Linux binaries aren't fully compatible to your system (and mine neither).

I'll just setup cmake to build lib3mf from source, that should make it easiest for most people I guess.

jschobben commented 3 years ago

Okay, just merged the cmake improvements for 3mfmerge to master. Let me know if it helps 🙂 Probably will improve the error checking in colorscad as well.

colorscad-tester commented 3 years ago

Thanks! I re-built and 3mfmerge works good.

I still had some issues with the std shell script

$ ./colorscad.sh simpletest.scad simpletest.3mf 
Get list of used colors
2 unique colors were found.

Create a separate .3mf file for each color
./colorscad.sh: line 118: wait: 1: no such job
./colorscad.sh: line 118: wait: 1: no such job
Jobs completed: 2/2 

Generate a merged .3mf file
Trouble while processing '[1, 1, 1, 1].3mf': Lib3MF Error 5 (The specified file could not be opened)
Will skip this file/color, and proceed anyway.
Trouble while processing '[1, 0, 0, 1].3mf': Lib3MF Error 5 (The specified file could not be opened)
Will skip this file/color, and proceed anyway.
Warning: 2 input files were skipped!

simpletest.3mf created, but there were some problems (merge step exit status: 1).
$ 1/2 [1, 1, 1, 1] Can't open input file './tmp.5aNn1FgiEj.csg'!
1/2 [1, 1, 1, 1] 
1/2 [1, 1, 1, 1] Warning: output is empty!
2/2 [1, 0, 0, 1] Can't open input file './tmp.5aNn1FgiEj.csg'!
2/2 [1, 0, 0, 1] 
2/2 [1, 0, 0, 1] Warning: output is empty!

During debugging I figured out it was the backgrounding doing something weird. Once I got rid of that it worked fine. So I wrote up an alternative using parallel rather then that backgrounding setup. I also added in getopts to take in options as I needed to pass through var's into openscad while generating objects.

$ ./colorscad-new.sh -i simpletest.scad -o simpletest.3mf 
Get list of used colors
2 unique colors were found.
#####
[1, 1, 1, 1]
[1, 0, 0, 1]
#####

Create a separate .3mf file for each color
[1, 1, 1, 1]
[1, 0, 0, 1]
[1, 1, 1, 1] Starting
[1, 1, 1, 1] Geometries in cache: 1
[1, 1, 1, 1] Geometry cache size in bytes: 728
[1, 1, 1, 1] CGAL Polyhedrons in cache: 0
[1, 1, 1, 1] CGAL cache size in bytes: 0
[1, 1, 1, 1] Total rendering time: 0:00:00.000
[1, 1, 1, 1]    Top level object is a 3D object:
[1, 1, 1, 1]    Facets:          6
[1, 1, 1, 1] finished at /tmp/tmp.26fokmUF4Q/[1, 1, 1, 1].3mf
[1, 0, 0, 1] Starting
[1, 0, 0, 1] Geometries in cache: 1
[1, 0, 0, 1] Geometry cache size in bytes: 728
[1, 0, 0, 1] CGAL Polyhedrons in cache: 0
[1, 0, 0, 1] CGAL cache size in bytes: 0
[1, 0, 0, 1] Total rendering time: 0:00:00.000
[1, 0, 0, 1]    Top level object is a 3D object:
[1, 0, 0, 1]    Facets:          6
[1, 0, 0, 1] finished at /tmp/tmp.26fokmUF4Q/[1, 0, 0, 1].3mf

###  Completed openscad CSG generation  ###

Generate a merged .3mf file

simpletest.3mf created successfully.
$ ./colorscad-new.sh -h
Usage: ./colorscad-new.sh -i <input scad file> -o <output file>

Options
  -D  Variable to pass to Openscad, quoting hell, does some weird bits but input like
        you would give openscad direct works.  For example: -D 'var1="foofly"' -D 'var2="another thing"'
  -e  Openscad extra (freeform extra options to pass to Openscad)
  -f  Force, this will overwrite the output file if it exists
  -h  This msg you are reading
  -i  Input file
  -o  Output file must not yet exist, and must have as extension either '.amf' or '.3mf'.
  -p  MAX_PARALLEL_JOBS (defualt is 8) reduce if you're low on RAM.

I will make a pull request with this version if you want, I just need to touch up a few things.

colorscad-tester commented 3 years ago

Just wanted to say thanks. I generated 30 some multi-color labels from CSV's. Everything works great!

As I mentioned I had to update the bash script to make it work and I needed to have a way to give variable to openscad during generation to get all my labels to have the correct text and such so I added a way to do that. As mentioned in the pull feel free to use or not use. https://github.com/jschobben/colorscad/pull/3

So happy you made this and very grateful for your support making it work on my setup. Getting all those labels made would have been a huge pain if I had to output STL's for all the colors. I am sure I will use it more in the future as well.

colorscad-tester commented 3 years ago

I guess I can self-close this issue? You fixed it so its all good now!