How to dynamicly load/release imstk resource?

There is one case, the renderwindow is the created by another dialog button command, while the renderwindow is served as the viewer in iMSTK. If the renderwindow need to be hidden and reshow for some reseason. If I just hide the renderwindow, it complaints that “D:\imstk\iMSTK\out\build\x64-Debug\External\VTK\src\Rendering\OpenGL2\vtkOpenGLState.cxx, line 694
Error glDepthFunc1 OpenGL errors detected
0 : (1286) Invalid framebuffer operation” and something like this. The renderwindow has nothing. So I have a question:
If I hide the renderwindow, the iMSTK resources:e.g. SceneManager SimulationManager and so on should be deal with in some way? for example stop render, or clean all these resources? Is there exmaples about how to dynamically alloc scene/viewer/manager and release them?

You mean you create the VTKViewer via a button and add it later?

Standalone usage of VTKViewer looks like this:

auto scene = std::make_shared<Scene>("Empty Scene");

VTKViewer viewer;
viewer.setActiveScene(scene);
viewer.init();
// Render 100 empty frames
for (int i = 0; i < 100; i++)
{
    viewer.update();
}
viewer.uninit();

You should not need to hide and show the viewer again to create a VTKViewer by a button.

Also we don’t have a function in our API to hide the VTKViewer. Though you could get the vtkRenderWindow and do it there:

auto scene = std::make_shared<Scene>("Empty Scene");

VTKViewer viewer;
viewer.setActiveScene(scene);
viewer.init();
auto vtkRenWin = viewer.getVtkRenderWindow();
for (int i = 0; i < 10000; i++)
{
	if (i == 5000)
	{
		vtkRenWin->SetShowWindow(false);
	}
	viewer.update();
}
viewer.uninit();

You cannot remove a Module (SceneManager or VTKViewer) from the SimulationManager at the moment. So they cannot be cleaned up unless the program exits. Feel free to contribute those functions though. If you do not use SimulationManager and manage the updates of SceneManager and VTKViewer yourself as above, then you can easily let them go out of reference/release.

Also if you’re looking on how to stop the simulation:

SimulationManager simManager;
// ... Setup Your SimulationManager ...
simManager.requestStatus(ModuleDriverStopped);

You can also use simManager.requestStatus(ModuleDriverPaused); to pause.

Or you can pause individual modules. Such as pause simulation but not rendering: SceneManager::setPaused. Or pause only rendering VTKViewer::setPaused