From: amerke <art...@ud...> - 2020-07-31 11:25:49
|
hi, i've problems with core dumps using ruby, gtk and tcp connections. my application is much larger, but here a minimized version: GTK code (is also attached): ##################################################### require 'gtk3' require 'cairo' class DummyArray def initialize @array=[ "M",2,48.83,1.95,"L",8,50.55,0.0,62.27,0.0,63.91,5.0,48.83,1.95,"M",2,0.0,22.42,"L",8,0.0,16.95,9.77,13.2,7.27,28.44,0.0,22.42,"M",2,5.39,49.61,"L",8,0.0,48.52,0.0,35.63,0.47,35.08,5.39,49.61,"M",2,0.0,80.7,"L",6,0.0,68.28,9.38,70.31,0.0,80.7,"M",2,90.23,46.56,"L",6,100.0,35.55,100.0,48.52,90.23,46.56,"M",2,100.0,16.95,"L",6,100.0,22.42,95.47,18.67,100.0,16.95,"M",2,100.0,68.28, "L",8,100.0,80.78,99.14,81.72,94.45,67.11,100.0,68.28,"M",2,50.55,100.0,"L",6,58.98,90.47,62.27,100.0,50.55,100.0,"M",2,23.44,78.67,"L",6,33.59,67.19,38.52,81.72,23.44,78.67,"M",2,40.47,15.39,"L",6,25.39,12.34,35.63,0.86,40.47,15.39,"M",2,59.61,39.77,"L",6,59.14,24.38,72.66,31.56,59.61,39.77,"M",2,45.78,36.95,"L",6,55.23,36.48,50.94,45.0,45.78,36.95, "M",2,48.98,24.38,"L",6,43.67,16.41,53.2,15.86,48.98,24.38,"M",2,22.58,10.08,"L",6,13.52,13.13,15.47,3.75,22.58,10.08,"M",2,18.28,30.47,"L",6,21.33,39.53,11.95,37.58,18.28,30.47,"M",2,25.23,40.86,"L",6,26.41,25.55,39.06,34.22,25.23,40.86,"M",2,13.67,63.13,"L",6,13.13,47.73,26.64,54.92,13.67,63.13,"M",2,17.66,68.52,"L",6,21.72,77.19,12.11,76.25,17.66,68.52,"M",2,52.34,49.06, "L",6,44.14,62.11,36.95,48.52,52.34,49.06,"M",2,52.42,79.84,"L",6,60.08,66.56,67.73,79.84,52.42,79.84,"M",2,47.42,76.25,"L",6,42.19,68.28,51.72,67.73,47.42,76.25,"M",2,79.14,31.48,"L",6,87.11,26.17,87.73,35.7,79.14,31.48,"M",2,81.64,20.08,"L",6,74.92,6.25,90.23,7.34,81.64,20.08,"M",2,67.97,10.86,"L",6,68.52,20.39,59.92,16.09,67.97,10.86,"M",2,73.59,73.36,"L",6,81.48,68.2,82.11,77.73,73.59,73.36, "M",2,63.59,49.06,"L",6,64.22,58.59,55.62,54.3,63.59,49.06,"M",2,79.53,43.83,"L",6,84.45,58.36,69.38,55.31,79.53,43.83,"M",2,90.23,95.16,"L",6,92.19,85.78,99.3,92.11,90.23,95.16,"M",2,86.17,81.48,"L",6,82.34,96.33,71.41,85.55,86.17,81.48,"M",2,22.11,97.34,"L",6,6.8,97.34,14.45,84.06,22.11,97.34,"M",2,38.2,93.05,"L",6,29.14,96.09,31.09,86.72,38.2,93.05, "Z",0 ] end def render(cr) i= 0 size= @array.size while i < size e= @array[i] case e when 'M', 'L' count= @array[i+1] j= i + 2 i= j + count while j < i x= @array[j] y= @array[j+1] if e == 'M' cr.move_to(x, y) else cr.line_to(x, y) end j += 2 end when 'Z' count= @array[i+1] j= i + 2 i= j + count cr.close_path else raise end end end end class ArtScrollCanvas < Gtk::Grid def initialize super @user_zoom= 1.0 @darea = Gtk::DrawingArea.new @darea.hexpand= true @darea.vexpand= true @darea.signal_connect('configure-event') do print "\n darea_configure_callback" update_adjustments_and_paint(0.0, 0.0) end @darea.signal_connect "draw" do |_, cr| paint(cr) end attach(@darea, 0, 0, 1, 1) update_adjustments_and_paint(0.0, 0.0) end def update_adjustments_and_paint(dx= 0.0, dy= 0.0) @darea.queue_draw_area(0, 0, @darea.allocation.width, @darea.allocation.height) end def paint(cr) cr.set_source_rgba(1, 1, 1, 1) cr.paint cr.set_source_rgba(1, 0, 0, 1) DummyArray.new.render(cr) #DummyDirect.new.render(cr) cr.fill end end class ArtApplicationWindow < Gtk::ApplicationWindow def initialize(application) super(application) signal_connect('destroy') do #Gtk.main_quit application.quit end set_title 'Art' set_size_request(600, 400) @canvas = ArtScrollCanvas.new @vbox = Gtk::Box.new(:vertical, 0) @vbox.pack_start(@canvas, :expand => true, :fill => true, :padding => 0) add(@vbox) show_all end end # ArtApplicationWindow class ArtApp < Gtk::Application def initialize super("org.gtk.exampleapp", :handles_open) signal_connect('activate') do |application| window = ArtApplicationWindow.new(application) window.present end end end begin ss = Gio::SocketService.new ss.add_inet_port(4321) ss.signal_connect("incoming") do |_, conn, _| print "\n#############################################################" print "\nconn.local_address: ", conn.local_address print "\nconn.local_address.family: ", conn.local_address.family print "\nconn.remote_address: ", conn.remote_address print "\nconn.class: ", conn.class print "\nconn.input_stream.fd: ", conn.input_stream.fd print "\nconn.input_stream.socket.fd: ", conn.input_stream.socket.fd # prevents closing the connection (at least in c code) Gtk::Loader.reference_gobject(conn) Gtk::Loader.reference_gobject(conn.input_stream) Gtk::Loader.reference_gobject(conn.input_stream.socket) Gtk::Loader.reference_gobject(conn.output_stream) Gtk::Loader.reference_gobject(conn.output_stream.socket) channel= GLib::IOChannel.new(conn.input_stream.socket.fd) channel.add_watch(GLib::IOChannel::IN) do print "\n>>> ", conn.input_stream.socket.fd len= conn.input_stream.socket.available_bytes input= conn.input_stream.read(len) print "\ninput= ", input conn.output_stream.write("OK\n") GLib::Source::CONTINUE true end true end ss.start end GLib::Timeout.add(10000) do print "\ntimer" GLib::Source::CONTINUE end app = ArtApp.new app.run ################################################# SIMPLE client: require 'socket' class Comm def initialize(socket, verbose: false) @socket= socket @sio= StringIO.new @verbose= verbose end def close @socket.close end def <<(str) @sio << str end def send str= @sio.string @socket.write(str) print "\n>>>\nsending: ", str if @verbose @sio.reopen res= @socket.readline print "\nres= \"", res, "\"" if @verbose res end end server_socket = TCPSocket.open("localhost", 4321) comm= Comm.new(server_socket, verbose: true) i= 1000000 while true i += 1 comm << i.to_s comm.send sleep(0.025) # 40 per s end in the beginning everything seems ok, but after the client is lauched resizing the GTK window leads to core dumps after approx. 1000 messages (sometimes much less, but sometimes much later). Shortening the @array in DummyArray leads to less core dumps, therefore the array is that large. i've read https://ruby-gnome2.osdn.jp/hiki.cgi?tips_threads but don't know how this would apply to my program ... cheers artur |