简体   繁体   English

Gtk2多线程gdk_pixbuf_get_from_drawable问题

[英]Gtk2 Multi Thread gdk_pixbuf_get_from_drawable Questions

Hi there fellow GTKers 你好GTKers

I am in a situation where I am writing a plug in for Firefox which is a GTK2 app. 我正在为Firefox编写插件,这是一个GTK2应用程序。 I need to execute gdk_pixbuf_get_from_drawable , now this function needs to run on the main thread. 我需要执行gdk_pixbuf_get_from_drawable ,现在这个函数需要在主线程上运行。

I read this article: http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness 我读了这篇文章: 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 g_threads_init() - 我不这样做,因为我无法在libgdk-x11-2.0.so.0找到此函数,也无法在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? 多次运行gdk_threads_init是否安全? 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? 可以多次运行gtk_init(0, null)吗?

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. 程序接收信号SIGSEGV,分段故障。

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

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. Firefox会为你做gtk_init,如果你在主线程上,你不需要任何线程的东西。 The most you could need, if FF does use GDK thread stuff, would be the enter and leave. 你可能需要的最多,如果FF确实使用GDK线程的东西,将是进入和离开。

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. 尝试设置MALLOC_CHECK_ = 2并在gdb中运行,或尝试在valgrind下运行,以查找内存错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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