yitzchak / common-lisp-jupyter

A Common Lisp kernel for Jupyter along with a library for building Jupyter kernels.
https://yitzchak.github.io/common-lisp-jupyter
MIT License
225 stars 28 forks source link

Error with image widget #88

Open shamazmazum opened 2 years ago

shamazmazum commented 2 years ago

Hi. I am running common-lisp-jupyter-20211207180130 from Ultralisp on SBCL 2.2.0 and have the following jupyter packages

vasily@vonbraun:~ % pkg info | grep noteb
py38-nbclient-0.5.9            Client library for executing notebooks
py38-notebook-6.4.6            Web-based notebook environment for interactive computing
vasily@vonbraun:~ % pkg info | grep jupyter
py38-jupyter-client-6.1.12_1   Jupyter protocol implementation and client libraries
py38-jupyter-core-4.9.1        Jupyter core package
py38-jupyter-server-1.13.2     The backend to Jupyter web applications
py38-jupyterlab-3.1.14         JupyterLab server extension
py38-jupyterlab-pygments-0.1.2 Pygments theme using JupyterLab CSS variables
py38-jupyterlab-server-2.10.2  JupyterLab Server
py38-jupyterlab-widgets-1.0.2  JupyterLab extension for Jupyter/IPython widgets

The problem is with jupyter-widgets:image widget. I run an example which draws the Julia set. Right after creation of a widget there is no image. I think this is incorrect, because you have (update instance) right at the end of initialize-instance method. 20220126_08h11m57s_grim

When I press some buttons on other widgets the image is drawn: 20220126_08h12m03s_grim but I have this in the console from where jupyter is started: 20220126_08h12m13s_grim

When I remove this method from src/message.lisp the memory corruption problem is gone. I think it tries to free some foreign memory twice.

(defmethod initialize-instance :after ((instance message) &rest initargs &key &allow-other-keys)
  (declare (ignore initargs))
  (let ((buffers (message-buffers instance)))
    (when buffers
      (trivial-garbage:finalize
        instance
        (lambda () (mapcar (lambda (buffer)
                             (static-vectors:free-static-vector buffer))
                           buffers))))))

But this does not solve the first problem. Practically, I have two image widgets and one integer scroller. When the scroller's value is changed a function is called which redraws both images. The first image is redrawn each time the value of that scroller is changed and the second image is redrawn only occasionally.

shamazmazum commented 2 years ago

My code is here

The result is the following: 20220126_08h38m27s_grim Two images must be identical but they are not.

yitzchak commented 2 years ago

This is probably due to bad finalization logic in my use of static-vectors.

Also, for your code sample you just posted a link back to this issue. Can you post at least a snippet of the code that produces the image comparison widget above?

shamazmazum commented 2 years ago

Oh, sorry. Here is a correct link. Those raw files are voxel spaces with dimensions sidexsidexside and one byte per voxel. I attach one so you can play test.raw.zip

https://gist.github.com/shamazmazum/e3d7e54f3bef21b612ced296057f4f9d