Gjs callbacks getting called during GC, apparently due to GLib.idle_add()

I’m trying to port a WebGL game to run in gjs, but after it’s been running for a few seconds, it starts getting errors that it’s tried to call a JS callback during a GC cycle. I haven’t done any of the things it lists as possible causes, like overriding vfuncs that get called when widgets are cleaned up. There are no widgets being created and destroyed at the time the errors happen, but I suppose it could be ones left over from the previous “screen”, being harvested belatedly.

I was using a GLib.idle_add() callback in JS to continually call Gtk.GLArea.queue_render(), and initially the errors said the offending function was “SourceFunc”. Unfortunately the stack trace is useless, it stops at Gio.Application.run(). I wrote another mini-library so that the callback could be written entirely in C, but this resulted in similar errors when it tried to call the GLArea’s “render” signal handler (another JS callback). So gtk_gl_area_queue_render() probably doesn’t literally queue a render request, but results in the render signal being emitted immediately.

It seems to me that gjs is allowing callbacks set by g_idle_add() to run concurrently with critical phases of GC. Although it cancels the callback rather than letting it crash, the app is beyond recovery by then. It’ s either causing the GC to get stuck in an infinite cycle, or failing to clear some flag, because if I try to wait out the GC by returning TRUE from the C callback to let it keep trying until it succeeds, it never does succeed. The console just gets flooded with those warnings until I kill the app.

Is there a way I can set up a C function to check whether the GC is running before trying to go ahead and do something that results in calling a JS callback?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.