Martin Kielhorn | 17 Dec 2009 20:03

window reopening bug and fix

Hi,
the test program in the bottom doesn't work as
expected in slime on my linux systems:
It should do the following:
when calling (run) with C-M-x it opens a window.
When pressing ESC in this window it will close.
When calling (run) again slime is destroyed.

One work around I found is to call (reinit) before calling (run) the second time.

The problem is that *glut-initialized-p* isn't reset to nil after leaving
the main loop in glut/main.lisp:
;; this is the fix:
(defun main-loop ()
  (without-fp-traps
    (%glutMainLoop))
  (setf *glut-initialized-p* nil) ; add this line to fix the bug
  init))




;; this is the test program:
#.(progn
  (require :asdf)
  (require :cl-opengl)
  (require :cl-glut)
  (require :cffi))

(defpackage #:mk
  (:use #:cl #:gl #:cffi))
(in-package #:mk)

(defcallback draw :void ()
  (clear :color-buffer)
  (with-primitives :lines
    (vertex 1 0)
    (vertex 0 1))
  (glut:swap-buffers))

(defcallback key :void ((key :uchar) (x :int) (y :int))
  (declare (ignore x y))
  (case (code-char key)
    (#\Esc (glut:leave-main-loop))))

(defun run ()
  (glut:init)
  (glut:init-display-mode :double :rgb)
  (glut:create-window "test")
  (glut:display-func (callback draw))
  (glut:keyboard-func (callback key))
  (glut:main-loop))


(defun reinit ()
  (with-foreign-objects ((argcp :int) (argv :pointer))
    (setf (mem-ref argcp :int) 1)
    (with-foreign-string (str "test")
      (setf (mem-ref argv :pointer) str)
      (glut::%glutInit argcp argv))))

--
Martin Kielhorn
Randall Division of Cell & Molecular Biophysics
King's College London, New Hunt's House
Guy's Campus, London SE1 1UL, U.K.
tel: +44 (0) 207 848 6519,  fax: +44 (0) 207 848 6435

_______________________________________________
cl-opengl-devel mailing list
cl-opengl-devel <at> common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cl-opengl-devel
Luís Oliveira | 20 Dec 2009 01:32
Picon
Gravatar

Re: window reopening bug and fix

Hello Martin,

On Thu, Dec 17, 2009 at 7:03 PM, Martin Kielhorn
<kielhorn.martin <at> googlemail.com> wrote:
> the test program in the bottom doesn't work as
> expected in slime on my linux systems:
> It should do the following:
> when calling (run) with C-M-x it opens a window.
> When pressing ESC in this window it will close.
> When calling (run) again slime is destroyed.

I found a patch laying around with a fix for this; I've pushed it to
the repository. Let me know if it fixes your problem.

--

-- 
Luís Oliveira
http://r42.eu/~luis/

Gmane