Add fix and doc for Mac OpenGL crash

CURA-4726
This commit is contained in:
Lipu Fei 2017-12-21 15:42:48 +01:00
parent 84a24a582c
commit df1d3bf569
2 changed files with 42 additions and 0 deletions

View file

@ -4,6 +4,7 @@
import sys import sys
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QOpenGLContext
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from UM.Application import Application from UM.Application import Application
@ -13,6 +14,7 @@ from UM.Logger import Logger
from UM.Math.Color import Color from UM.Math.Color import Color
from UM.Mesh.MeshBuilder import MeshBuilder from UM.Mesh.MeshBuilder import MeshBuilder
from UM.Message import Message from UM.Message import Message
from UM.Platform import Platform
from UM.PluginRegistry import PluginRegistry from UM.PluginRegistry import PluginRegistry
from UM.Preferences import Preferences from UM.Preferences import Preferences
from UM.Resources import Resources from UM.Resources import Resources
@ -24,6 +26,7 @@ from UM.View.GL.OpenGLContext import OpenGLContext
from UM.View.View import View from UM.View.View import View
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from cura.ConvexHullNode import ConvexHullNode from cura.ConvexHullNode import ConvexHullNode
from cura.CuraApplication import CuraApplication
from .NozzleNode import NozzleNode from .NozzleNode import NozzleNode
from .SimulationPass import SimulationPass from .SimulationPass import SimulationPass
@ -414,6 +417,23 @@ class SimulationView(View):
return True return True
if event.type == Event.ViewActivateEvent: if event.type == Event.ViewActivateEvent:
# FIX: on Max OS X, somehow QOpenGLContext.currentContext() can become None during View switching.
# This can happen when you do the following steps:
# 1. Start Cura
# 2. Load a model
# 3. Switch to Custom mode
# 4. Select the model and click on the per-object tool icon
# 5. Switch view to Layer view or X-Ray
# 6. Cura will very likely crash
# It seems to be a timing issue that the currentContext can somehow be empty, but I have no clue why.
# This fix tries to reschedule the view changing event call on the Qt thread again if the current OpenGL
# context is None.
if Platform.isOSX():
if QOpenGLContext.currentContext() is None:
Logger.log("d", "current context of OpenGL is empty on Mac OS X, will try to create shaders later")
CuraApplication.getInstance().callLater(lambda e=event: self.event(e))
return
# Make sure the SimulationPass is created # Make sure the SimulationPass is created
layer_pass = self.getSimulationPass() layer_pass = self.getSimulationPass()
self.getRenderer().addRenderPass(layer_pass) self.getRenderer().addRenderPass(layer_pass)

View file

@ -2,10 +2,13 @@
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import os.path import os.path
from PyQt5.QtGui import QOpenGLContext
from UM.Application import Application from UM.Application import Application
from UM.Logger import Logger
from UM.Math.Color import Color from UM.Math.Color import Color
from UM.PluginRegistry import PluginRegistry from UM.PluginRegistry import PluginRegistry
from UM.Platform import Platform
from UM.Event import Event from UM.Event import Event
from UM.View.View import View from UM.View.View import View
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
@ -13,6 +16,8 @@ from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
from UM.View.RenderBatch import RenderBatch from UM.View.RenderBatch import RenderBatch
from UM.View.GL.OpenGL import OpenGL from UM.View.GL.OpenGL import OpenGL
from cura.CuraApplication import CuraApplication
from . import XRayPass from . import XRayPass
## View used to display a see-through version of objects with errors highlighted. ## View used to display a see-through version of objects with errors highlighted.
@ -52,6 +57,23 @@ class XRayView(View):
def event(self, event): def event(self, event):
if event.type == Event.ViewActivateEvent: if event.type == Event.ViewActivateEvent:
# FIX: on Max OS X, somehow QOpenGLContext.currentContext() can become None during View switching.
# This can happen when you do the following steps:
# 1. Start Cura
# 2. Load a model
# 3. Switch to Custom mode
# 4. Select the model and click on the per-object tool icon
# 5. Switch view to Layer view or X-Ray
# 6. Cura will very likely crash
# It seems to be a timing issue that the currentContext can somehow be empty, but I have no clue why.
# This fix tries to reschedule the view changing event call on the Qt thread again if the current OpenGL
# context is None.
if Platform.isOSX():
if QOpenGLContext.currentContext() is None:
Logger.log("d", "current context of OpenGL is empty on Mac OS X, will try to create shaders later")
CuraApplication.getInstance().callLater(lambda e = event: self.event(e))
return
if not self._xray_pass: if not self._xray_pass:
# Currently the RenderPass constructor requires a size > 0 # Currently the RenderPass constructor requires a size > 0
# This should be fixed in RenderPass's constructor. # This should be fixed in RenderPass's constructor.