wglMakeCurrent failed in MakeCurrent() happens every time the window is called to render

import vtk
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton
from PyQt5.QtCore import pyqtSignal, QObject
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor # type: ignore

import os

os.environ[‘MESA_GL_VERSION_OVERRIDE’] = ‘3.3’

class Communicate(QObject):
orientation_signal = pyqtSignal(list)

class MainWindow(QMainWindow):
def init(self, parent=None):
super(MainWindow, self).init(parent)
self.comm = Communicate()
#self.comm.orientation_signal.connect(self.apply_orientations)

    # Set up the main window
    self.setWindowTitle('Live Simulation')
    self.frame = QWidget()
    self.vl = QVBoxLayout()
    self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
    self.vl.addWidget(self.vtkWidget)

    self.zero_yaw_button = QPushButton("Calibrate Direction")
    self.zero_yaw_button.clicked.connect(self.set_yaw_zero_direction)
    self.vl.addWidget(self.zero_yaw_button)

    # Renderer and render window setup
    self.renderer = vtk.vtkRenderer()
    self.vtkWidget.GetRenderWindow().AddRenderer(self.renderer)
    self.interactor = self.vtkWidget.GetRenderWindow().GetInteractor()

    self.style = vtk.vtkInteractorStyleTrackballCamera()
    self.interactor.SetInteractorStyle(self.style)

    # Load the tool and tooth
    self.tool = self.load_stl("3D_GUI_test/hp.stl", (1, 0, 0))
    self.tooth = self.load_stl("3D_GUI_test/Flossable_Teeth_-_Mandible.stl", (0, 0, 1))
    self.tooth.SetPosition(0, 0, 0)
    self.renderer.AddActor(self.tool)
    self.renderer.AddActor(self.tooth)
    self.renderer.SetBackground(1, 1, 1)
    self.renderer.ResetCamera()
    self.camera = self.renderer.GetActiveCamera()
    self.camera.SetPosition(95.94370844261519, 116.70196856544167, 45.06343624793749)
    self.camera.SetFocalPoint(168.4618377685547, 110.82939910888672, 11.044604063034058)
    self.camera.SetViewUp(0.4276590806389098, 0.053961019016033104, 0.9023280551849385)
    self.camera.SetDistance(80.3159205648567)

    self.pivot_point = (150.7989392026424, 110.90430094394753, 12.482846069096375)
    self.transform = vtk.vtkTransform()
    self.transform.Translate(self.pivot_point)
    self.tool.SetUserTransform(self.transform)

    self.tool.GetProperty().SetOpacity(0.25)

    self.frame.setLayout(self.vl)
    self.setCentralWidget(self.frame)

    self.interactor.Initialize()

    self.yaw_zero_hp_offset = 0
    self.yaw_zero_jaw_offset = 0
    self.jaw_roll_offset = 0
    self.jaw_pitch_offset = 0

    # Initialize current_orientations with a default value
    self.current_orientations = [0, 0, 0, 0, 0, 0]

def set_yaw_zero_direction(self):
    # This method is called when the button is pressed to set the current yaw as zero direction
    current_yaw_hp = float(self.current_orientations[2])
    current_yaw_jaw = float(self.current_orientations[5])

    self.yaw_zero_hp_offset = 90 - current_yaw_hp
    self.yaw_zero_jaw_offset = 270 - current_yaw_jaw
    self.jaw_roll_offset = float(self.current_orientations[3])
    self.jaw_pitch_offset = float(self.current_orientations[4])

def load_stl(self, filename, color):
    reader = vtk.vtkSTLReader()
    reader.SetFileName(filename)
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(reader.GetOutputPort())
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(color)
    return actor

def apply_orientations(self, orientations):
    # Store the current orientations for reference
    self.current_orientations = orientations

    # Compute the relative orientation of the tool with respect to the tooth
    relative_roll = float(orientations[3]) - self.jaw_roll_offset - float(orientations[0])
    relative_pitch = float(orientations[4]) - self.jaw_pitch_offset - float(orientations[1])
    jaw_yaw = float(orientations[5]) + self.yaw_zero_jaw_offset
    hp_yaw = float(orientations[2]) + self.yaw_zero_hp_offset

    relative_yaw = jaw_yaw - hp_yaw
    print(f'hp: {orientations[2]}, jaw: {orientations[5]}, relative yaw: {relative_yaw}')

    # Apply the relative orientation to the tool
    self.tool.SetOrientation(relative_roll - 180, relative_pitch, hp_yaw)
    self.vtkWidget.GetRenderWindow().Render()

Here is the code, and every time apply_orientations is called from another loop it throws that error 7 times and nothing comes up.

1 Like