Hello Everyone,
I develop a Java swing application that has a user interface that allows moving the JComponents in a live JFrame.
I can totally instanciate my vtkPanels and add them to a JFrame I am building and then the jframe is working nicely when I call the .setVisible(true) on it.
However, the vtkPanel as some issues when I remove the vtkPanel from a live/shown JFrame and then reatach the vtkPanel in another place in the JFrame.
After I add the vtkPanel to another place in the JFrame, I often have an error writing this on the standart error stream:
2025-08-25 18:06:13.149 ( 117.401s) [ ]vtkWin32OpenGLRenderWin:267 ERR| vtkWin32OpenGLRenderWindow (000001271CF8C510): wglMakeCurrent failed in MakeCurrent(), error: 䧐᥄ħ
Usually lots of lines with this error, with just the timestamp modified.
Sometimes it seems the vtkPanel is still working properly after this, most often not (black vtkPanel), and sometimes it crashes the java app.
I gather the issue it that vtk doesn’t like to render its content while the vtkPanel is not visible and not attached to anything so I tried to override the Render()
method to not call the vtkPanel.Render() original one when the vtkPanel is not added to anything, but it doesn’t seem to help that much.
I even tried to override addNotify()
and removeNotify()
to make Render()
do nothing as long as addNotify()
has not been called, but it does not work either.
Then just a few minutes ago I thought maybe the call to rw.setForceMakeCurrent()
should be called only once for the component and so I modified it to test:
vtkPanel.java
@Override
public void addNotify()
{
super.addNotify();
windowset = 0;
rw.SetForceMakeCurrent();
rendering = false;
}
=> vtkRenderWindow.java
private native void SetForceMakeCurrent_125();
public void SetForceMakeCurrent()
{
if ( !setForceMakeCurrentDone ) {
System.out.println("vtkRenderWindow.SetForceMakeCurrent()");
setForceMakeCurrentDone= true;
SetForceMakeCurrent_125();
}
}
boolean setForceMakeCurrentDone;
but it did not help either.
In a nutshell, it seems the first call to Render()
after the vtkPanel is reattached make it crash. I don’t know exactly why of what I can do to make it work properly.
Do you happen to know what I should do to ensute vtk is not lost when I rearrange the swing swing components in a live window?
Thanks in advance!
PS: by the way, I managed to find a workaround by… instantiating a new vtkPanel after I have finished to rearrange my components, but I don’t like this at all of course!