Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene rendering is broken #1

Closed
kwabenantim opened this issue May 25, 2023 · 4 comments
Closed

Scene rendering is broken #1

kwabenantim opened this issue May 25, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@kwabenantim
Copy link
Member

kwabenantim commented May 25, 2023

Describe the bug
See PyChaste/issues/5:

Returning a VTK Renderer to Python is broken, causing failures in tutorials and breaking of rendering in Jupyter notebook.s

To Reproduce
Build and install PyChaste from source with VTK ==7.1.1, which is the oldest available version on Ubuntu 22.04.

In a Jupyter notebook:

import chaste 
chaste.init()
from chaste.visualization import JupyterNotebookManager, VtkScene2

scene = VtkScene2()
nbManager = JupyterNotebookManager()
nbManager.vtk_show(scene)

Error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: Unregistered type : vtkSmartPointer<vtkRenderer>

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 nbManager.vtk_show(scene)

File ~/Chaste/build/projects/PyChaste/python/chaste/visualization/fortests.py:134, in JupyterNotebookManager.vtk_show(self, scene, width, height, output_format, increment)
    132 renderWindow = vtk.vtkRenderWindow()
    133 renderWindow.SetOffScreenRendering(1)
--> 134 renderWindow.AddRenderer(scene.GetRenderer())
    135 renderWindow.SetSize(width, height)
    136 renderWindow.Render()

TypeError: Unable to convert function return value to a Python type! The signature was
	(self: chaste.visualization._chaste_project_PyChaste_visualization.VtkScene2) -> vtkSmartPointer<vtkRenderer>
@kwabenantim
Copy link
Member Author

Interestingly, this bug exists for vtk 6.3.0 as well when compiling with 2019 PyChaste and 2019 Chaste on Ubuntu 18.04. Rebuilding an old vtk in #2 may not necessarily resolve the broken rendering.

@kwabenantim
Copy link
Member Author

The last working version seems to be the one used in the docker image from 2016 i.e. Pychaste v3.4.2 which uses Boost Python bindings. From v3.4.3, PyChaste was migrated to PyBind11.

@kwabenantim
Copy link
Member Author

@MILeach
Copy link
Collaborator

MILeach commented Jun 6, 2023

After the merge of #5, animations can be displayed in the notebook, but there is a memory leak which quickly (in the order of 30 seconds - few minutes) crashes the host machine.

Steps to Fix

  • Test equivalent simulation code outside of the notebook and with no visualisation to check the leak is not part of the simulation. No leak present
  • Check that halting the offending cell in the notebook pauses the memory leak. Memory leak pauses when the cell is stopped
  • Try running a single step simulation in the notebook and checking whether the leak continues - this will identify whether it is simulation code or an issue with the visualisation code. Leak does not continue to occur for short simulations - these reach completion and memory usage stops increasing.
  • Investigate visualistion code + JupyterSceneModifier2 for any obvious memory hogs, e.g saving every frame/instantiation every frame of something that might not get garbage collected.
    • fortests.py:132 - new vtkRenderWindow created every frame
    • fortests.py:146 - new vtkWindowToImageFilter created every frame
    • fortests.py:150 - new vtkPNGWriter created every frame
    • fortests.py:151 - SetWriteToMemory(1) - check if vtk clears these

Fixed

The vtkRenderWindows being created each frame were not GC'd. Fixed by having a single render window as a class member of JupyterNotebookManager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants