Threads, gtkmozembed and segmentfault -heeeelp-

Hello everyone,
My programm has a scheduler in the background (openwferu-scheduler
0.9.16.1404). which should replace the content/(children) of a toplevel
window.

but i get a segment fault when i add and remove a embedded mozilla, i
tried everything!! now I m out of ideas

here are 2 basic sample how it (not)works:
→ two with embeded mozilla is is not working :-/
→ one with Buttons as content this is working :slight_smile:

does anyone have a idea whats the problem ? anyone a idea for a
workaround ?

thanks ahead !!

Philipp

#####################################################################
require ‘gtkmozembed’

Gtk.init

gtk = Gtk::Window.new
Gtk::MozEmbed.set_profile_path(ENV[‘HOME’] + ‘/.mozilla’, ‘RubyGecko’)
moz = Gtk::MozEmbed.new

gtk.add(moz)
gtk.show_all
moz.load_url(“https://mail.google.com/”)

Thread.new do
Gtk.main
end

sleep 5
gtk.child.destroy
moz = Gtk::MozEmbed.new
gtk.add(moz)
gtk.show_all
moz.load_url(“http://www.google.com/”)

###################
error################################################

(irb):30: [BUG] Segmentation fault

ruby 1.8.6 (2007-06-07) [i486-linux]

#########################################################################

require ‘gtkmozembed’

Thread.abort_on_exception = true

Gtk.init

@gtk
@moz
@gtk = Gtk::Window.new
Gtk::MozEmbed.set_profile_path(ENV[‘HOME’] + ‘/.mozilla’, ‘RubyGecko’)

Thread.new do
@moz = Gtk::MozEmbed.new
@gtk.add(@moz)
@gtk.show_all
@moz.load_url(“https://mail.google.com/”)
end

Thread.new do
sleep 10
@gtk.child.destroy

@moz = Gtk::MozEmbed.new
@gtk.add(@moz)
@gtk.show_all
@moz.load_url(“http://www.google.com/”)
end

Gtk.main

###################
error################################################

(irb):30: [BUG] Segmentation fault

ruby 1.8.6 (2007-06-07) [i486-linux]

#########################################################################

#############################################################################
require ‘gtkmozembed’

Gtk.init

gtk = Gtk::Window.new
moz = Gtk::Button.new “AAAAA”
gtk.add(moz)
gtk.show_all

Thread.new do
Gtk.main
end

sleep 5
gtk.child.destroy
moz = Gtk::Button.new “bbbbbb”
gtk.add(moz)
gtk.show_all

################### working !!!

##############################################################################

but i get a segment fault when i add and remove a embedded mozilla, i
tried everything!! now I m out of ideas

Here is a code-snipplet that was posted here some time before:

module Gtk
# Thread-safety stuff.
# Loosely based on booh, by Guillaume C…

PENDING_CALLS_MUTEX = Mutex.new
PENDING_CALLS = []

def self.thread_protect(&proc)
    if Thread.current == Thread.main
        proc.call
    else
        PENDING_CALLS_MUTEX.synchronize do
            PENDING_CALLS << proc
        end
    end
end

def self.thread_flush
    if PENDING_CALLS_MUTEX.try_lock
        for closure in PENDING_CALLS
            closure.call
        end
        PENDING_CALLS.clear
        PENDING_CALLS_MUTEX.unlock
    end
end

def self.init_thread_protect
    Gtk.timeout_add(100) do
        PENDING_CALLS_MUTEX.synchronize do
            for closure in PENDING_CALLS
                closure.call
            end
            PENDING_CALLS.clear
        end
        true
    end
end

end
Gtk.init_thread_protect

When you use unsafe operations with GTK use it like this
Gtk.thread_protect{
@gtk.add(@moz)
@gtk.show_all
}

I think this should get rid of the segfaults. (I haven’t tried with
mozembed)