Closed wildptr closed 3 years ago
If the cairo context used for drawing is created outside the event handler, the program does not crash, but exposed regions don't get updated.
This is normal, see the note “due to double-buffering, Cairo contexts created in a GTK+ expose event handler cannot be cached and reused between different expose events”.
So I think it might be necessary to add a finalization function that allows the user to explicitly destroy the cairo object.
I do not see the problem in keeping the cairo context in memory a while longer until it gets garbage collected. I'd like to make sure to understand the problem first.
Does your problem happens with the gtk_demo
in the sources?
Could you try to recompile the current version and let me know?
@bobot I will rebase again when the fix is confirmed to work (sorry).
Yes, this happens with gtk_demo
on Mac (not yet tried on other OS's). The exposed region of the window does not get updated when window is enlarged.
May you try to add some printing (and flushing!) in the #expose
callback to make sure it is indeed triggered?
I have added some printing to the test. You can do
dune build @tests-gtk --force
(but then the printing will eb delayed by dune
) or, after dune build @tests-gtk
run _build/default/tests-gtk/alloc.exe
(to see the printing immediately).
@wildptr Any news?
Sorry for being unresponsive for a long time. I missed notifications for your comments :( I'm busy with work these days and I will come back with this issue some time later.
Please reopen if with more info if it is not fixed.
I'm drawing to GTK drawing areas using cairo. All drawing is done via a cairo context created within the expose event handler. However, I have run into 2 problems (which seem to be Mac-specific):
When the window containing the drawing area is closed, the program always crashes at the following minor GC (SIGSEGV in some GDK quartz backend function called by
cairo_surface_destroy
).When the window is resized, the exposed region of the drawing area is not updated at all. I have no idea why.
(On Windows and Linux everything looks fine.)
However I have found a workaround: perform GC manually in order to finalize the cairo object when the expose event handler is done with it. However, this is inefficient, since all that's needed is calling the finalizer of the cairo object, which is to my knowledge not possible in OCaml. So I think it might be necessary to add a finalization function that allows the user to explicitly destroy the cairo object.
If the cairo context used for drawing is created outside the event handler, the program does not crash, but exposed regions don't get updated.
I'm fairly new to GTK and cairo so please correct me if I get something wrong.