1

I am trying to get a pixbuf, i used gdk3 method and gdk2 method and both are failing. Using ctypes here but issue is not ctypes, I'm sure of it, so tagging with that would confuse the ctypes folk. So I only put gtk tags.

GDK3 method

var cRootWin = ostypes.API('gdk_screen_get_root_window')(cScreen);
var cWidth = ostypes.API('gdk_screen_get_width')(cScreen);
var cHeight = ostypes.API('gdk_screen_get_height')(cScreen);

no errors happen. I then run this code:

var src_x = 0;
var src_y = 0;
var pixbuf = ostypes.API('gdk_pixbuf_get_from_window')(cRootWin, src_x, src_y, cWidth, cHeight);

and it then throws this:

(firefox:2624): GLib-GObject-WARNING **: cannot register existing type 'GdkWindow'

(firefox:2624): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed

(firefox:2624): Gdk-CRITICAL **: gdk_pixbuf_get_from_window: assertion 'GDK_IS_WINDOW (src)' failed

Does anyone know whats up? I can't figure this out for a long time now :(

GDK2 method

In place of the gdk 3 method I tried the gdk2 method and it crashes:

var cRootWin = ostypes.API('gdk_screen_get_root_window')(cScreen);
var cWidth = ostypes.API('gdk_screen_get_width')(cScreen);
var cHeight = ostypes.API('gdk_screen_get_height')(cScreen);
var dest_x = 0;
var dest_y = 0;
var src_x = 0;
var src_y = 0;
var pixbuf = ostypes.API('gdk_pixbuf_get_from_drawable')(null, cRootWin, null, src_x, src_y, dest_x, dest_y, cWidth, cHeight);

This crashes the browser with this message in terminal:

[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
firefox: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
firefox: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.

I can't figure this out for a couple days, can you please advise.

Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • 1
    How is this running? As a Firefox extension? – andlabs May 21 '15 at 21:03
  • Thanks @andlabs for the attn, yep it uses js-ctypes https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Standard_OS_Libraries – Noitidart May 21 '15 at 21:58
  • 1
    That explains the errors then; respectively: you can't mix GTK+ 2 (which Firefox uses) and GTK+ 3, and your extension is run on a different thread. Unfortunately I'm not familiar with Firefox extensions, sorry; I can only suggest trying to use an idle callback, but I'm not sure if this will actually work... – andlabs May 22 '15 at 01:03
  • Ah thank you @andlabs ! You are like Sherlock Holmes!! Yep I am running this code in another thread! But then how come the GTK+2 method of `gdk_pixbuf_get_from_drawable` would cause a crash thats not mixing right? Do I have to call `XInitThreads` somehow ? – Noitidart May 22 '15 at 02:27
  • @andlabs its also interesting in that Firefox already does call XInitThreads: https://dxr.mozilla.org/mozilla-central/source/toolkit/xre/nsAppRunner.cpp#3713 so it shouldnt crash right? – Noitidart May 22 '15 at 03:44
  • 1
    I don't know. It's probably something to do with process separation. An expert in Firefox extensions will need to answer now. I know for GTK+ 3 that idle callbacks can be done with `GLib.idle_add()`; other than that I dunno about doing it in Python or with GTK+ 2. Sorry :/ – andlabs May 23 '15 at 01:24
  • Thank ou very much @andlabs this helps out immensely! – Noitidart May 23 '15 at 01:50

0 Answers0