When trying to use event controllers (say adding event controllers to a drawing area to make it interactive), one tends to write code like:
drawingArea <- GTK.drawingAreaNew
drawingAreaClicks <- GTK.gestureClickNew
GTK.gestureSingleSetButton drawingAreaClicks 0
GTK.widgetAddController drawingArea drawingAreaClicks
_ <- GTK.afterGestureClickPressed drawingAreaClicks $ \ nbClicks x y -> do
button <- GTK.gestureSingleGetCurrentButton drawingAreaClicks
handleAction $ MouseClick nbClicks button (Point2D x y)
However, adding the drawingAreaClicks event controller to the widget disowns it, thus causing warnings like the following
WARNING: Accessing a disowned pointer <0x00000000649d0680>, this may lead to crashes.
• Callstack for the unsafe access to the pointer:
CallStack (from HasCallStack):
notOwnedWarning, called at .\\Data\\GI\\Base\\ManagedPtr.hs:194:25 in haskell-gi-ba_-0.25.0-e54f296d31598ac13124f52c63d6d957a696495e:Data.GI.Base.ManagedPtr
unsafeManagedPtrCastPtr, called at .\\GI\\Gtk\\Objects\\GestureSingle.hs:584:17 in gi-gtk-4.0.4-f0386fac927306f5dfd453fb2b725fbcae403b0c:GI.Gtk.Objects.GestureSingle
gestureSingleGetCurrentButton, called at Example.hs:6:13
• The pointer was disowned at:
CallStack (from HasCallStack):
disownManagedPtr, called at .\\Data\\GI\\Base\\ManagedPtr.hs:335:15 in haskell-gi-ba_-0.25.0-e54f296d31598ac13124f52c63d6d957a696495e:Data.GI.Base.ManagedPtr
disownObject, called at .\\GI\\Gtk\\Objects\\Widget.hs:5847:20 in gi-gtk-4.0.4-f0386fac927306f5dfd453fb2b725fbcae403b0c:GI.Gtk.Objects.Widget
widgetAddController, called at Example.hs:2:22
@garetxe indicated that there might be a way to avoid these warnings
- In C this is not an issue, because the callback receives the pointer to self, but in the Haskell bindings we omit it
- This is not very hard to fix (we just need to expose the self argument in the callback somehow), but I need to think about the best way to expose this in the bindings
When trying to use event controllers (say adding event controllers to a drawing area to make it interactive), one tends to write code like:
However, adding the
drawingAreaClicksevent controller to the widget disowns it, thus causing warnings like the following@garetxe indicated that there might be a way to avoid these warnings