Skip to content

Commit

Permalink
Change OpenGL execution to a forked subprocess, and run it before wxw…
Browse files Browse the repository at this point in the history
…indows is imported. Newer versions of wx can use OpenGL under the hood, resulting in "glutInit being called a second time" and often segfaulting the process.
  • Loading branch information
jterrace committed Aug 12, 2012
1 parent b82c1f9 commit 51fd677
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
2 changes: 2 additions & 0 deletions COLLADATestSuite.py
Expand Up @@ -4,6 +4,8 @@
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Materials.
# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
import Core

import wx
import os
import sys
Expand Down
24 changes: 3 additions & 21 deletions Core/Logic/FExecution.py
Expand Up @@ -5,8 +5,6 @@
# in all copies or substantial portions of the Materials.
# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

import OpenGL.GL
import OpenGL.GLUT
import os
import os.path
import shutil
Expand All @@ -17,16 +15,14 @@

import Core.Common.FUtils as FUtils
import Core.Common.FGlobals as FGlobals
import Core.gl
from Core.Common.FConstants import *
from Core.Common.FSerializable import *
from Core.Common.FSerializer import *
from Core.Logic.FJudgement import *
from Core.Logic.FJudgementContext import *
from Core.Logic.FResult import *

GL_VENDOR = None
GL_RENDERER = None

class FExecution(FSerializable, FSerializer):
def __init__(self, executionDir = None):
"""Creates the FExecution."""
Expand All @@ -52,22 +48,8 @@ def __init__(self, executionDir = None):
self.__judgingLogs = {}
self.__checksum = ""

global GL_VENDOR, GL_RENDERER
if GL_VENDOR is None:
OpenGL.GLUT.glutInit(sys.argv)
# need to create a window before glGetString will return something
OpenGL.GLUT.glutInitWindowSize(640,480)
winId = OpenGL.GLUT.glutCreateWindow("dummy")
OpenGL.GLUT.glutDisplayFunc(self.__DummyDisplayFunc)
GL_VENDOR = OpenGL.GL.glGetString(OpenGL.GL.GL_VENDOR)
GL_RENDERER = OpenGL.GL.glGetString(OpenGL.GL.GL_RENDERER)
OpenGL.GLUT.glutDestroyWindow(winId)

self.__environment["GL_VENDOR: "] = GL_VENDOR
self.__environment["GL_RENDERER: "] = GL_RENDERER

def __DummyDisplayFunc(self):
pass
self.__environment["GL_VENDOR: "] = Core.gl.GL_VENDOR
self.__environment["GL_RENDERER: "] = Core.gl.GL_RENDERER

# executionDir must be absolute path and it should be empty!
def Clone(self, executionDir):
Expand Down
3 changes: 3 additions & 0 deletions Core/__init__.py
@@ -1,3 +1,6 @@
# import this before wx because of compatibility issues
import gl

import wx

# some versions of wx module use Colour instead of Color depending on locale
Expand Down
30 changes: 30 additions & 0 deletions Core/gl.py
@@ -0,0 +1,30 @@
import sys
import multiprocessing

GL_VENDOR = None
GL_RENDERER = None

def get_opengl_info(q):
import OpenGL.GL
import OpenGL.GLUT

def __DummyDisplayFunc():
pass

OpenGL.GLUT.glutInit(sys.argv)
# need to create a window before glGetString will return something
OpenGL.GLUT.glutInitWindowSize(640,480)
winId = OpenGL.GLUT.glutCreateWindow("dummy")
OpenGL.GLUT.glutDisplayFunc(__DummyDisplayFunc)
GL_VENDOR = OpenGL.GL.glGetString(OpenGL.GL.GL_VENDOR)
GL_RENDERER = OpenGL.GL.glGetString(OpenGL.GL.GL_RENDERER)
OpenGL.GLUT.glutDestroyWindow(winId)

q.put((GL_VENDOR, GL_RENDERER))

if GL_VENDOR is None:
q = multiprocessing.Queue()
p = multiprocessing.Process(target=get_opengl_info, args=(q,))
p.start()
GL_VENDOR, GL_RENDERER = q.get()
p.join()

0 comments on commit 51fd677

Please sign in to comment.