vispy / jupyter_rfb

Remote Frame Buffer for Jupyter
https://jupyter-rfb.readthedocs.io
MIT License
60 stars 12 forks source link

kernel dies if widget is resized to a very large height, this sometimes happens unintentionally #62

Closed kushalkolar closed 1 year ago

kushalkolar commented 1 year ago

This is a bizarre issue that seems to happen if the widget is left unattended for a long period of time (~30+ minutes?) . If you then try to resize it after this long unattended period it elongates vertically downward extremely fast, as if I suddenly increased my mouse cursor speed by an order of magnitude. The kernel then crashes.

I'll try to reproduce and provide more info soon.

almarklein commented 1 year ago

Interesting ... 😕

almarklein commented 1 year ago

The latest changes did change some stuff related to the sizing, so with a bit of luck this is now fixed ... ?

kushalkolar commented 1 year ago

This still happens but I think I figured out some more details, it's occurs when dragging the canvas resize handlers causes the browser to scroll the page very quickly, this then leads to the canvas being elongated to a very large size. If the browser scrolls very fast it can be difficult to stop this. Browsers can sometimes scroll much faster than shown in the example video below, I think the scroll rate is higher if the webpage page is longer.

Maybe a workaround is to set a max_size for the canvas dims?

https://user-images.githubusercontent.com/9403332/223005069-667c1e91-eac7-49ac-a54f-60dfb7e4e4f1.mp4

almarklein commented 1 year ago

Aha, that makes sense!

Maybe a workaround is to set a max_size for the canvas dims?

That could help. I think it's also worth looking into a solution to disable the browser's autoscrolling behavior. E.g. some ideas here. Will try to find some time this week to look into it.

almarklein commented 1 year ago

I tried, but I have not yet been able to reproduce this. I tried to mimic your example by putting a simple canvas inside an hbox and vbox, but no luck yet.

Would it be possible to provide a minimal example for which the effect happens on your machine? E.g. does it also happen with the hello world example of jupyter_rfb? Does it only happen when embedded in ipywidgets? Or does it only happen with a fastplotlib Plot?

kushalkolar commented 1 year ago

I just tried playing with this more:

  1. The auto-scroll behavior isn't always triggered, I can't seem to figure out exactly what triggers it.
  2. If you resize the RFB widget while scrolling fast:
    • the hello world example doesn't cause the kernel to die
    • simple pygfx example (shown below) does cause the kernel to die
import pygfx
import numpy
from wgpu.gui.auto import WgpuCanvas

canvas = WgpuCanvas()
renderer = pygfx.WgpuRenderer(canvas)

a = numpy.random.rand(512, 512).astype(numpy.float32)

tex = pygfx.Texture(a, dim=2).get_view()
geo = pygfx.Geometry(grid=tex)
mat = pygfx.ImageBasicMaterial(clim=(0, 1))

img = pygfx.Image(geo, mat)

cam = pygfx.OrthographicCamera(512, 512)
cam.position.set(256, 256, 1)

scene = pygfx.Scene()
scene.add(img)

canvas.request_draw(lambda: renderer.render(scene, cam))

canvas
almarklein commented 1 year ago

Still can't replicate it, but this should do the trick: #70.