Andreas Davour writes:
Several things are going on here.
> (defvar *screen* (sdl:create-surface 640 480))
>
> (defvar *bild* (sdl:load-image
> "/home/ante/Hack/Lisp/src/SDL/good-hack.bmp"))
>
> (defun sdl-tst ()
> (sdl:with-init ()
> (sdl:window 640 480 :title-caption "Testing")
>
> ;; the main loop
> (sdl:with-events ()
> (:quit-event ()
> (sdl:free-surface *screen*)
> (sdl:free-surface *bild*)
> t)
> (:idle (sdl:clear-display (sdl:color))
> ; this is were it happens
> (sdl:draw-surface *bild* :surface sdl:*default-surface*)
> (sdl:update-display)))))
>
*SCREEN* is unused so you can delete it. For both *BILD* and *SCREEN* you
are attempting to create the SDL surfaces prior to initializing the SDL
library. Bad things may happen.
A minor point is that sdl:*DEFAULT-SURFACE* is NIL unless you assign a
SURFACE to it using the macro SDL:WITH-SURFACE, for example:
(sdl:window 640 480 :title-caption "Testing")
...
(sdl:with-surface (a-surface sdl:*default-display*)
(sdl:draw-surface *bild*))
But DRAW-SURFACE anticipates this infraction and sets :SURFACE to
*default-display* in the event that :SURFACE is NIL (The assumption being
that the intent is to draw to the screen). For example, the following is
also legal;
(sdl:window 640 480 :title-caption "Testing")
...
(sdl:draw-surface *bild*)
But the error you are seeing is caused by the following:
(:quit-event ()
(sdl:free-surface *bild*)
t)
You free the SURFACE in *BILD*. But then the macro WITH-EVENTS executes
:IDLE once more prior to exiting the event loop. Then in :IDLE you attempt
to DRAW *BILD* to display but because *BILD* is already freed the result is
a crash to the debugger.
So, thanks for identifying a nasty little bug in WITH-EVENTS. I'll fix that.
As a workaround, don't free *BILD*. The SURFACE is freed automatically upon
garbage collection.
Try the following and see what happens.
(defvar *bild* nil)
(defun sdl-tst ()
(sdl:with-init ()
(sdl:window 640 480 :title-caption "Testing" :icon-caption "Testing")
(setf *bild* (sdl:load-image
"/home/ante/Hack/Lisp/src/SDL/good-hack.bmp"))
(unless *bild*
(error "Cannot load /home/ante/Hack/Lisp/src/SDL/good-hack.bmp"))
;; the main loop
(sdl:with-events ()
(:quit-event () t)
(:idle (sdl:clear-display (sdl:color))
(sdl:draw-surface *bild*)
(sdl:update-display)))))
- Luke
_______________________________________________
application-builder mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/application-builder