简体   繁体   中英

Gtk2 Multi Thread gdk_pixbuf_get_from_drawable Questions

Hi there fellow GTKers

I am in a situation where I am writing a plug in for Firefox which is a GTK2 app. I need to execute gdk_pixbuf_get_from_drawable , now this function needs to run on the main thread.

I read this article: http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness

And learned that to call this from my thread I have to first call:

  1. g_threads_init() - i dont do this though as i cant find this function defined in libgdk-x11-2.0.so.0 nor in libgtk-x11-2.0.so.0
  2. gdk_threads_init()
  3. gtk_init(0, null)
  4. gdk_threads_enter()
  5. gdk_pixbuf_get_from_drawable(....)
  6. gdk_threads_leave()

So this works fine but everytime my user clicks the button to take a screen shot I execute all these functions again. So my questions are:

  1. Is it safe to run gdk_threads_init multiple times? The thread was never destroyed so i shouldnt have to run it right? but is it safe if i do?
  2. Is it ok to run gtk_init(0, null) multiple times?

The reason I ask this is because when I test by repeatedlycalling the function typically after second time the app slows down and eventually crash with message:

Program received signal SIGSEGV, Segmentation fault.

0x00007f09382138b4 in XGetImage () from /usr/lib/x86_64-linux-gnu/libX11.so.6

You shouldn't need any of this; Firefox will have done gtk_init for you, and if you're on the main thread you don't need any of that thread stuff. The most you could need, if FF does use GDK thread stuff, would be the enter and leave.

The segfault is most likely caused by an unrelated mistake. Try setting MALLOC_CHECK_=2 and running in gdb, or try running under valgrind, to find memory errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM