enthought/mayavi

wglMakeCurrent failed in MakeCurrent() on Windows machine

FennisRobert opened this issue · 1 comments

I am making an application in Python with a PyQt gui following the application example. The idea is that I can have a permanent window open running mayavi that I can control from an external python process. I am leaving out quite a bit of code in the following but I believe my mistake will be obvious.

When updating or changing the plots with new content I get a lot of warnings on windows only, it still plots but vtk isn't happy.

2024-07-24 10:13:59.124 (  20.398s) [1ACBC272DD16888B]vtkWin32OpenGLRenderWin:255    ERR| vtkWin32OpenGLRenderWindow (000001774555C8B0): wglMakeCurrent failed in MakeCurrent(), error: Þíáõؽ┼À
2024-07-24 10:13:59.128 (  20.402s) [1ACBC272DD16888B]vtkWin32OpenGLRenderWin:255    ERR| vtkWin32OpenGLRenderWindow (000001774555C8B0): wglMakeCurrent failed in MakeCurrent(), error: Þ«Çõؽ┼À
2024-07-24 10:13:59.132 (  20.407s) [1ACBC272DD16888B]vtkWin32OpenGLRenderWin:255    ERR| vtkWin32OpenGLRenderWindow (000001774555C8B0): wglMakeCurrent failed in MakeCurrent(), error: Þô░õؽ┼À
2024-07-24 10:13:59.138 (  20.412s) [1ACBC272DD16888B]vtkWin32OpenGLRenderWin:255    ERR| vtkWin32OpenGLRenderWindow (000001774555C8B0): wglMakeCurrent failed in MakeCurrent(), error: ÞñÇõؽ┼À

The hopefully relevant code (with some redacted functions that likely won't be the issue omitted.

class MayaviCanvas(HasTraits):
    scene = Instance(MlabSceneModel, ())

    @on_trait_change('scene.activated')
    def update_plot(self):
        self.scene.background = (1, 1, 1)

    view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                     height=600, width=800, show_label=False),
                resizable=True # We need this to resize with the parent widget
                )
    
    def update_plots(self):
        pass
        
    def quiver3d(self, *args, **kwargs):
        obj = self.scene.mlab.quiver3d(*args, **kwargs)
        obj.glyph.color_mode = 'color_by_scalar'
        
    def points3d(self, *args, **kwargs):
        self.scene.mlab.points3d(*args, **kwargs)
    
    def plot3d(self, *args, **kwargs):
        self.scene.mlab.plot3d(*args, **kwargs)
        
    def surf(self, *args, **kwargs):
        self.scene.mlab.surf(*args, **kwargs)
        
    def mesh(self, *args, **kwargs):
        self.scene.mlab.mesh(*args, **kwargs)
        
    def trisurf(self, *args, **kwargs):
        self.scene.mlab.triangular_mesh(*args, **kwargs)
    
    def triangular_mesh(self, *args, **kwargs):
        self.scene.mlab.triangular_mesh(*args, **kwargs)
    

    def clear(self):
        self.scene.mlab.clf()
       
    def zoom(self, zoomlevel):
        f = self.scene.mlab.gcf()
        f.scene.camera.zoom(zoomlevel)

I fixed the issue myself. The error wasn't in this code but the fact that these functions such as clear where being called from an external thread. With the help of ChatGPT I managed to figure out to use a Signal object to call from this external thread instead which would call these functions instead of directly from the external thread. So if anyone finds this, maybe its your external thread.