pythreejs icon indicating copy to clipboard operation
pythreejs copied to clipboard

Mouse control gets stuck and objects disappear when using multiple Renderers inside ipywidgets.interact

Open t-suzuki opened this issue 6 years ago • 4 comments

Hi, Thank you all for developing this awesome project!

Today I would like to report a peculiar behavior that when many (>=8 for example) Renderer()s are used inside a ipywidgets.interact function, OrbitControls() sometimes get stuck and objects in the scene disappear on some ordinary mouse operations (like L-dragging after R-dragging). However I am not sure this is a bug of pythreejs (maybe a bug of jupyter notebook, ipywidgets or even threejs?)

Please find repro code in the attached notebook (extension changed to .txt according to GitHub limitations). ManyRenderersInsideInteract.ipynb.txt

environment:

  • Windows 10 Pro 1809
  • Browser
    • Chrome: Version 74.0.3729.169 (Official Build) (64-bit)
    • Firefox: 67.0 (64bit)
  • Python 3.6.5 (x64)

jupyter==1.0.0 jupyter-client==5.2.3 jupyter-console==5.2.0 jupyter-core==4.4.0 jupyterlab==0.32.1 jupyterlab-launcher==0.10.5 pythreejs==2.0.2 ipywidgets==7.4.2

t-suzuki avatar Jun 05 '19 20:06 t-suzuki

Hi, and thanks for the kind words.

Browsers have a limit for how many concurrent webgl contexts it can have (typically 8 or 16), which is the likely cause for your >= 8. When pythreejs hits that limit, it will start switching out the webgl contexts with images, and re-purpose the contexts whenever it needs to draw. So if you have 8+ renderers each trying to update simultaneously, there is bound to be a performance hit.

That being said, the following things will be symptoms of a bug:

  • Completely glitchy interactions like you describe.
  • If it starts drawing all other renderers when you only interact with one (are you reusing objects across renderers?)

vidartf avatar Jun 11 '19 21:06 vidartf

I'll have a look at this later, but for now: Is there any output in the browser developer console when this happens? The console is typically accessible by pressing the F12 key on your keyboard when in the correct browser tab.

vidartf avatar Jun 11 '19 22:06 vidartf

Thanks for pointing out the number of WebGL contexts. It may be the trigger of the problem. However, the glitch only occurs when Renderer()s are used inside ipywidgets.interact but does not occur when directly IPython.display()ed. It suggests that the number of WebGL contexts is probably not the sole cause of the problem.

Also, the behavior happens even if single Renderer() with a very simple scene is updated once at a time and the others are not simultaneously updated. Therefore it does not seem to be a performance issue.

If it starts drawing all other renderers when you only interact with one (are you reusing objects across renderers?)

Sometimes, objects in other renderers disappear when interacting with another renderer. Renderer objects are not reused (calling create_renderer() each time to display a renderer; please find the code in the second cell of attached ipynb).

Developer console: I found some errors when running the problematic cell. It is recorded only once when the last cell is executed and no additional logs at the timing of the glitchy behavior. Error messages do not show up if renderers are directly passed to IPython.display() without ipywidgets.interact(). console

t-suzuki avatar Jun 18 '19 16:06 t-suzuki

In general, I would say that using pythreejs with interact is an anti-pattern. That being said, it might be that this is a symptom of an issue with pythreejs, so it might be worth looking into.

vidartf avatar Jun 18 '19 17:06 vidartf