We have a java application in which we are trying to utilize vtk. I have created a fairly simply MPR vtk pipeline using vtkImageResliceMapper and everything seems to work fine when I have just a single window using this pipeline, however, when I subsequently create a second window (i.e. viewport - not a vtk viewport) I get the following error msg when triggering a render request (around 90 of this same error msg happens all at once):
2025-08-31 15:58:15.551 ( 20.686s) [A9661B54375E57F9]vtkWin32OpenGLRenderWin:252 ERR| vtkWin32OpenGLRenderWindow (000001F439647E40): wglMakeCurrent failed in MakeCurrent(), error: The handle is invalid.(code 6)
The image seems to display ok and I am able to interact with it initially. We typically will create up to 4 of these viewports (standard 4 MPR views) and add some point, one or more of those viewports will just go blank when interacting with it. Each of these viewports has its own vtkRenderWindowPanel and related vtk objects. The only thing shared between them is the same vtkImageData object used as input. There is no additional error displayed when the viewport(s) go blank but I have no doubt it is related to the above error messages.
When having multiple vtkRenderWindowPanel’s in the same application, is there any sort of coordination that is required between them? Any idea of why those error messages are showing up? Any help would be greatly appreciated.
After some more debugging, I have found that the problem is related to some Swing/AWT component manipulation that our application is doing when adding new 3D rendering windows. It temporarily removes existing 3D windows from the Swing container via removeAll and then adds them back. Prior to removing them, the visibility on my vtk window is set to false and after adding it back, the visibility is set to true. It is actually at this point on the existing 3D vtk based window that the above wglMakeCurrent error shows up.
I am speculating that this Swing component manipulation is invalidating the window handle used by the underlying OpenGL context. Assuming this is the case, is there a VTK method to force the OpenGL context recreation or should I be disposing/recreating the vtkRenderWindow or any other suggestions?
Hello,
I have the exact same issue (multiples vtkCanvas and adding/removing them while they ar live, same error in the console, and in addition the canvas sometimes seem to work, most often freezes/turns black or sometimes the java program is crashing in the native code in vtk)
I have tried many many workarounds for days, it used to work quite badly even with a single vtkCanvas but now this simple case may be fixed, I only have issues when there are several vtkCanvas live.
Even if I have 3 vtkCanvas in my JFrame, and if I remove only one and put it back, it fails.
This is very strange as it does not if I have only one vtkCanvas in my JFrame, I would have assumed it would work since the instances are not the same?
Initially I was on vtk 9.2.6, I just downloaded & compiled the 9.5.1, I haven’t tried it yet but I will.
I seemed to have no issues if I recreate the vtkOpenGLRenderWindowjust when I add the vtkCanvas back to the JFrame as long as there is no vtkActor in, but………… but the wglMakeCurrent error is back if there is a simple vtkAxesActor in the scene…
I also tried to just instanciate a new vtkCanvas everytime, it worked but of course it’s a super bad solution (I would have to save all the cameras/light/whatever etc)
PS: What system are you using? On a Windows 10 with the 9.2.6 version it showed me some gibberish chars, not sure why the wide chars to chars conversion failed. I modified the C++ function to just get the getLastErrorCode() and indeed it’s 6 like you.
OK so maybe all the vtkCanvas could use the same renderWindow with ```canvas2.GetRenderWindow().SetSharedRenderWindow(rwFromCanvas1);
canvas3.GetRenderWindow().SetSharedRenderWindow(rwFromCanvas1);
//etc```
I haven’t tried it yet, I reaaaally need to sleep, I will be back later!