Lisp HUG Maillist Archive

Reloading images

Hi,

When a pane goes "out of screen", i.e. when it is removed from its layout, it seems like all images loaded onto the pane are released. So when the pane is readded to the layout, references to those images are not valid and any attempt to use them leads to an exception. This has led me into a pattern like this:

… in some display-callback
  (unless (and (slot-value pane 'loaded-image)
                   (slot-value (slot-value pane 'loaded-image) 'gp::representation))
        ;; Loaded image is not valid, so reload it
        (let ((image-object (gp:load-image pane (slot-value btn 'image))))
          (setf (slot-value btn 'loaded-image) image-object)))
        

While this works, it grows tedious if there are many images. Is there any way to avoid freeing of images while the pane is being hidden?

Erik


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Reloading images

Hi Erik,

I use images with the panes that contain them, so they are loaded at creation and freed at destruction.

I also use this to lazily load an image:

(defmethod slot-unbound (class (self status-indicator)
                               (slot-name (eql 'image)))
  (with-slots (image status) self
    (setf image (gp:load-image self status))))



Best,
Cam


On 12 sept. 2013, at 00:34, Erik Ronström <erik.ronstrom@doremir.com> wrote:


Hi,

When a pane goes "out of screen", i.e. when it is removed from its layout, it seems like all images loaded onto the pane are released. So when the pane is readded to the layout, references to those images are not valid and any attempt to use them leads to an exception. This has led me into a pattern like this:

… in some display-callback
 (unless (and (slot-value pane 'loaded-image)
                  (slot-value (slot-value pane 'loaded-image) 'gp::representation))
       ;; Loaded image is not valid, so reload it
       (let ((image-object (gp:load-image pane (slot-value btn 'image))))
         (setf (slot-value btn 'loaded-image) image-object)))


While this works, it grows tedious if there are many images. Is there any way to avoid freeing of images while the pane is being hidden?

Erik


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Re: Reloading images

>>>>> On Thu, 12 Sep 2013 00:34:41 +0200, Erik Ronström said:
> 
> Hi,
> 
> When a pane goes "out of screen", i.e. when it is removed from its layout,
> it seems like all images loaded onto the pane are released. So when the pane
> is readded to the layout, references to those images are not valid and any
> attempt to use them leads to an exception. This has led me into a pattern
> like this:
> 
> … in some display-callback
>   (unless (and (slot-value pane 'loaded-image)
>                    (slot-value (slot-value pane 'loaded-image) 'gp::representation))
>         ;; Loaded image is not valid, so reload it
>         (let ((image-object (gp:load-image pane (slot-value btn 'image))))
>           (setf (slot-value btn 'loaded-image) image-object)))
>         
> 
> While this works, it grows tedious if there are many images. Is there any
> way to avoid freeing of images while the pane is being hidden?

No, you can't avoid the freeing.

I recommend adding a :destroy-callback to the output-pane to set the
loaded-image slot to nil so you can detect that it needs to be reloaded.

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:35 UTC