In CLIM, How to display an image on an application pane in the correct way?

631 views Asked by At

I tried the approach written in the "image-viewer" example, but when I run that example, the program leaks memory. Every time that the function draw-pattern* was called the memory reported by (room) increased and eventually SBCL runs out of memory so the game is over.

I create the pattern with make-pattern-from-bitmap-file and then I display it with draw-pattern*. The code follows:

(ql:quickload 'mcclim)
(ql:quickload 'mcclim-gif-bitmaps)

(defpackage #:display-image
  (:use #:clim #:clim-lisp))

(in-package #:display-image)

(define-application-frame img-viewer ()
  ((img-pattern :initform 'nil))
  (:panes
   (int-pane (make-clim-interactor-pane :name 'interactor))
   (canvas-pane (make-clim-application-pane
         :name 'canvas
         :scroll-bars t
         :display-time :command-loop
         :display-function #'draw-image)))
  (:layouts
   (default
       (vertically (:min-height 650 :max-height 800)
         (3/4 (labelling (:label "Image") canvas-pane))
         (1/4 int-pane))))
  (:menu-bar t))

(defmethod draw-image ((frame img-viewer) stream)
  (with-slots (img-pattern) *application-frame*
    (if img-pattern
        (draw-pattern* stream img-pattern
               (/ (- (bounding-rectangle-width stream)
                     (pattern-width img-pattern)) 2)
               0))))

(define-img-viewer-command (com-quit :name t :menu t) ()
  (frame-exit *application-frame*))

(define-img-viewer-command (com-change-img :name t :menu t)
    ((img-pathname 'pathname
           :default (user-homedir-pathname)
           :insert-default t))
  (if (and (probe-file img-pathname)
           (string= "GIF" (string-upcase (pathname-type img-pathname))))
      (with-slots (img-pattern) *application-frame*
        (setf img-pattern
              (make-pattern-from-bitmap-file img-pathname
                                             :format :gif)))))

(run-frame-top-level (make-application-frame 'img-viewer)
0

There are 0 answers