shoes / shoes3

a tiny graphical app kit for ruby
http://walkabout.mvmanila.com
Other
181 stars 19 forks source link

svg branch - segfault in draw function #158

Closed passenger94 closed 8 years ago

passenger94 commented 8 years ago

Ouch ! segfault in draw function. Launch demo below (single svg file or a multi svg file), call bybug or manual Alt+; or Alt+? and svg disappears from parent slot, if you try to resize the window with the svg => crash ( Edit : can also crash directly ) ; with shoes irb Alt+= it crashes directly ; Shoes log Alt+/ and open file dialog Alt+. are fine

Shoes.app width: 800 do
    #cpath = "#{DIR}/Hqueen_simple.svg"
    cpath = "#{DIR}/Color_52_Faces.svg"

    #svgh2 = app.svghandle({:filename => cpath, :group => '#heart_queen'})
    svgh2 = app.svghandle({:filename => cpath, :group => '#g6186'})

    stack width: 400, height: 450 do
        background gray
        svg 392, 447, svgh2
    end
end

-e: [BUG] Segmentation fault at 0x00000000000000 ruby 2.1.7p400 (2015-08-18 revision 51632) [x86_64-linux]

-- Control frame information ----------------------------------------------- c:0002 p:---- s:0004 e:000003 CFUNC :draw c:0001 p:0000 s:0002 E:000958 TOP [FINISH]

-- Ruby level backtrace information ---------------------------------------- -e:0:in `draw'

-- C level backtrace information ------------------------------------------- ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(+0x1e3ffc) [0x7fdc55aa2ffc] vm_dump.c:690 ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(+0x78b13) [0x7fdc55937b13] fileops.c:1000 ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(rb_bug+0xb3) [0x7fdc55938763] fileops.c:1304 ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(+0x15bc03) [0x7fdc55a1ac03] ../sysdeps/x86_64/multiarch/strcpy-ssse3.S:655 /lib/x86_64-linux-gnu/libpthread.so.0(+0x10340) [0x7fdc556b1340] ../nptl/sysdeps/pthread/funlockfile.c:29 ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(st_lookup+0x19) [0x7fdc55a233a9] ../sysdeps/x86_64/multiarch/memcmp-ssse3.S:1087 ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(rb_class2name+0x51) [0x7fdc55a69581] variable.c:165 ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(rb_check_type+0x9c) [0x7fdc5593a71c] genops.c:455 ./shoes() [0x46bf78] ./shoes(shoes_svg_draw+0x129) [0x46c3b4] ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(+0x1d77ff) [0x7fdc55a967ff] vm_eval.c:118 ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(+0x1d84af) [0x7fdc55a974af] vm_eval.c:50 ~/.rvm/rubies/ruby-2.1.7/lib/../lib/libruby.so.2.1(rb_funcall+0xca) [0x7fdc55a97bba] vm_eval.c:592 ./shoes(shoes_canvas_draw+0x3c1) [0x4290c6] ............

ccoupe commented 8 years ago

If you build shoes with the -g debugging symbols the back traces are much more useful. There are many unfinished things with svg - the gc mark/free for example. I'm not convinced svg is wired into shoes properly.

passenger94 commented 8 years ago

yes, you explained that, just leaving a reminder of problems i step on while roaming around code :-) will do proper debug protocol, if you need it :-)

passenger94 commented 8 years ago

This one is a tough one ! it segfault when shoes in a repaint call is checking the type of self_t->svghandle in Data_Get_Struct(self_t->svghandle, shoes_svghandle, svghan) in shoes_svg_draw_surface https://github.com/Shoes3/shoes3/blob/svg/shoes/svg.c#L320

To me it seems that Shoes in this particular path of event doesn't know something about cSvgHandle Class or i suspect more probably RsvgHandle Objet This is happening at the very moment a new pure Shoes app is launched (manual or irb) by pure i mean no direct call to c shoes function, only ruby code - if i open manual or irb first, Then an app with an svg widget, everything works fine ! other windows are fine ( also tested a new windows with svg widgets embedded, also fine) - So my guess is that while triggering a repaint on owner app the launched app doesn't know about librsgv, it's weird and i obviously don't know what i'm talking about here ?? Maybe simply an #include directive somewhere else than canvas.h ?? Maybe we need to make a ruby RsvgHandle Class out of the RsvgHandle Objet ??

PS : this might be related to the warinngs shown when quitting the app by closing the window ...?

EDIT No ! the svg widget disappears THEN when repaint is triggered it's not there anymore, and Shoes don't find self_t->svghandle ! ==> Crash Now why is the widget disappearing ??????

passenger94 commented 8 years ago

Putting a guard before the call to Data_Get_Struct(self_t->svghandle, shoes_svghandle, svghan) so we don't crash

we indeed find our friend : (shoes:18946): Gtk-CRITICAL **: gtk_widget_queue_draw: assertion 'GTK_IS_WIDGET (widget)' failed

inspecting the value of self_t->svghandle when manual is launched gives surprising result :

"art.oval]], by offering the:angle1 and :angle2 styles. (in fact, you can mimick the oval method by setting :angle1 to 0 and :angle2 to shoes::two_pi.)"

self_t->svghandle is a String ! and a copy of the manual ??? memory issue ?

EDIT : a minimum app triggering the issue

Shoes.app width: 650, height: 550 do
    path1 = "#{DIR}/paris2.svg"

    stack width: 300, height: 350 do 
        svg path1, group: "#heart_7", width: 250, height: 280, margin: 20, displace_left: 30
    end

    button "Wreck me" do
        window do
            require 'irb/ruby-lex' # <== comment this for no crash
            para 'oops !'
        end
    end
end

Could you please try this, i'm wondering if it's not just my setup !?? some "require" leads to problems some not ... (it's not require by itself, the problem, i use it here because it shows the issue )

ccoupe commented 8 years ago

That example does crash, stack suggest shoes_svg_draw -> shoes_svg_draw_surface-> rb_check_type. I suspect garbage collection (manual or auto)

Edit: yes - shoes_svghandle_free is being called after the button push.

passenger94 commented 8 years ago

shoes_svg_draw -> shoes_svg_draw_surface-> rb_check_type

yes this is the reason of the crash, at the time shoes check for self_t->svghandle type, which should be T_DATA (12), with rb_check_type(), it's either nil T_NIL (0) or some random stuff like T_STRING (5) in case of Manual. This situation arise because something wrong happened just before, making the svghandle vanishing in the 15th dimension ...

Thanks, at least we know it's a real bug ...

garbage collection ... memory issue,... a pointer pointing to whatever pleases him at the moment, C is such a eccentric moody screwball !

ccoupe commented 8 years ago

Got it. add this line to svg.c, shoes_svg_mark() rb_gc_mark_maybe(svg->svghandle); I'll push it up later.

ccoupe commented 8 years ago

Please reopen issue if it fails again.

passenger94 commented 8 years ago

Excellent !!