[cl-gtk2-devel] how to send messages to a window?

Tamas Papp tkpapp at gmail.com
Thu Apr 22 15:13:21 UTC 2010


On Wed, 21 Apr 2010, Kalyanov Dmitry wrote:

> On Wednesday 21 April 2010 12:50:47, Tamas Papp wrote:
> > Hi,
> > 
> > How can I send an "expose" message to a window from _outside_ the main
> > loop?
> 
> Basically, you can't. You should call queue-widget-draw function inside main 
> loop by means of within-main-loop-and-wait (this macro will wait until your 
> code actually completes in the main loop and returns its return value) or 
> within-main-loop (this macro will not wait until your code finishes or even 
> starts executing and returns immediately). Call to this function marks the 
> widget area as invalidated and at the next occasion (at the next iteration of 
> gtk+ event loop) Gtk+ will repaint the widget.

Thanks, that's what I am doing now.

> > But when I call sync, sometimes I get "unmapped memory area" errors
> > for GObject callbacks.  The whole code is available here:
> > http://github.com/tpapp/cl-cairo2/tree/master/src/gtk2/
> 
> Could you provide more information, a stack trace? Where does this message 
> comes from - is it a Lisp exception or cairo error message or gtk error 
> message? Does it occur randomly or deterministically?

This is a Lisp exception, occurring randomly.  Backtrace is here:

Unhandled memory fault at #x40.
   [Condition of type SB-SYS:MEMORY-FAULT-ERROR]

Restarts:
 0: [RETURN-FROM-G-CLOSURE] Return value from closure
 1: [RETURN-FROM-CALLBACK] GTK::RETURN-FROM-CALLBACK
 2: [TERMINATE-THREAD] Terminate this thread (#<THREAD "cl-gtk2 main thread" RUNNING {100B0D1971}>)

Backtrace:
  0: (SB-SYS:MEMORY-FAULT-ERROR)
      [No Locals]
  1: ("foreign function: #x422670")
      [No Locals]
  2: ("foreign function: #x422750")
      [No Locals]
  3: ("foreign function: #x802837D7D8")
      [No Locals]
  4: (CL-CAIRO2::REPAINT-DRAWING-AREA #<CL-CAIRO2::CAIRO-DRAWING-AREA {100B243F71}>)
      Locals:
        SB-DEBUG::ARG-0 = #<CL-CAIRO2::CAIRO-DRAWING-AREA {100B243F71}>
  5: (GOBJECT::CALL-WITH-RESTARTS ..)
      Locals:
        SB-DEBUG::ARG-0 = #<FUNCTION (LAMBDA (CL-CAIRO2::WIDGET CL-CAIRO2::EVENT)) {1004F565A9}>
        SB-DEBUG::ARG-1 = (#<CL-CAIRO2::CAIRO-DRAWING-AREA {100B243F71}> ..)
  6: ((LAMBDA (GOBJECT::CLOSURE GOBJECT::RETURN-VALUE GOBJECT::COUNT-OF-ARGS GOBJECT::ARGS GOBJECT::INVOCATION-HINT GOBJECT::MARSHAL-DATA)) ..)
      Locals:
        SB-DEBUG::ARG-0 = #.(SB-SYS:INT-SAP #X0070ACB0)
        SB-DEBUG::ARG-1 = #.(SB-SYS:INT-SAP #X7FFFE9C6AD20)
        SB-DEBUG::ARG-2 = 2
        SB-DEBUG::ARG-3 = #.(SB-SYS:INT-SAP #X0070A410)
        SB-DEBUG::ARG-4 = :<NOT-AVAILABLE>
        SB-DEBUG::ARG-5 = :<NOT-AVAILABLE>
  7: ((LAMBDA (SB-ALIEN::ARGS-POINTER SB-ALIEN::RESULT-POINTER FUNCTION)) 17592139437423 17592139437422 #<FUNCTION (LAMBDA #) {1002DC8D09}>)
      Locals:
        SB-DEBUG::ARG-0 = 17592139437423
        SB-DEBUG::ARG-1 = 17592139437422
        SB-DEBUG::ARG-2 = #<FUNCTION (LAMBDA ..) {1002DC8D09}>
  8: ("foreign function: #x422670")
  9: ("foreign function: #x40CFB0")
 10: ("foreign function: #x20101234")
 11: ("foreign function: #x8016E59B08")
 12: ((LAMBDA (SB-ALIEN::ARGS-POINTER SB-ALIEN::RESULT-POINTER FUNCTION)) 17592139438208 17592139438207 #<FUNCTION (LAMBDA #) {1002DCB089}>)
 13: ("foreign function: #x422670")
 14: ("foreign function: #x40CFB0")
 15: ("foreign function: #x20101B1B")
 16: ("foreign function: #x803CFDF088")
 17: ((LAMBDA ()))
 18: ((FLET #:WITHOUT-INTERRUPTS-BODY-[BLOCK369]374))
 19: ((FLET SB-THREAD::WITH-MUTEX-THUNK))
 20: ((FLET #:WITHOUT-INTERRUPTS-BODY-[CALL-WITH-MUTEX]300))
 21: (SB-THREAD::CALL-WITH-MUTEX ..)
 22: (SB-THREAD::INITIAL-THREAD-FUNCTION)
 23: ("foreign function: #x422670")
 24: ("foreign function: #x419307")
 
> The code looks fine except for several issues:
> 1) in create-gtk2-xlib-context you can use within-main-loop-and-wait instead 
> of within-main-loop
> 2) (incf (sync-counter-object)) is not atomic - you should use a real lock 
> (bordeaux-threads provides portable locking API)

Thanks for the hints.

Tamas




More information about the cl-gtk2-devel mailing list