bharling
19-02-2008 14:15:15
I Found a bug, i think. I've been developing a quick screensaver in PO, and compiling it with py2exe to produce an executable. I guess this could be a py2exe problem, but quite often ( apparently at random ) it crashes badly on exit, displaying that nasty blue-screen and restarting the PC, too quickly for me to see whats going on. When I force it to run in directX mode, everything seems fine ( including when compiled into an exe ). Also it runs fine in the interpreter in either openGL or directX. heres the code - based on the demo renderCreate:
This problem only seems to occur when a compiled exe is produced, I'll update the drivers for my gfx card (NV Geforce 8800 GT) now and see if that solves the issue.
import ogre.renderer.OGRE as ogre
import ogre.io.OIS as OIS
import sys
import os
import os.path
def getPluginPath():
"""Return the absolute path to a valid plugins.cfg file."""
paths = [os.path.join(os.getcwd(), 'plugins.cfg'),
'/etc/OGRE/plugins.cfg',
os.path.join(os.path.dirname(os.path.abspath(".")),
'plugins.cfg')]
for path in paths:
if os.path.exists(path):
return path
sys.stderr.write("\n"
"** Warning: Unable to locate a suitable plugins.cfg file.\n"
"** Warning: Please check your ogre installation and copy a\n"
"** Warning: working plugins.cfg file to the current directory.\n\n")
raise ogre.Exception(0, "can't locate the 'plugins.cfg' file", "")
class ApplicationFramework(object):
def __init__(self):
self.client = None
self.root = ogre.Root( getPluginPath() )
ogre.LogManager.getSingleton().setLogDetail( ogre.LoggingLevel.LL_LOW )
config = ogre.ConfigFile()
config.load('resources.cfg' )
section_iter = config.getSectionIterator()
while section_iter.hasMoreElements():
section_name = section_iter.peekNextKey()
settings = section_iter.getNext()
for item in settings:
ogre.ResourceGroupManager.getSingleton().addResourceLocation(item.value, item.key, section_name)
renList = self.root.getAvailableRenderers()
miscParams = ogre.NameValuePairList()
bOpenGL = False
for r in renList:
#print "Renederer",r.getName(), r, type(r)
if r.getName().startswith( "OpenGL" ) and bOpenGL:
self.root.setRenderSystem ( r )
miscParams["FSAA"] = "1"
#miscParams["Full Screen"] = "Yes"
miscParams["Full Screen"] = "Yes"
miscParams["VSYNC"] = "Yes"
miscParams["Video Mode"]= "1024 X 768 @ 32-bit colour"
miscParams["title"]="ScreenSaver"
#stdout.write("Using OpenGL renderer")
else:
if r.getName().startswith('Direct') and not bOpenGL:
self.root.setRenderSystem ( r )
#stdout.write("Using DirectX renderer")
miscParams["VSYNC"] = "YES"
miscParams["Anti aliasing"] = "Level4"
self.root.initialise(False)
self.renderWindow = self.root.createRenderWindow( "ScreenSaver", 1024, 768, True, miscParams )
self.sceneManager = self.root.createSceneManager(ogre.ST_GENERIC,"Test")
self.camera = self.sceneManager.createCamera( "RootCam" )
self.camera.nearClipDistance = 5
self.camera.setPosition (180, 300, 335)
self.camera.lookAt(0,0,0)
ogre.TextureManager.getSingleton().defaultNumMipmaps = 5
ogre.ResourceGroupManager.getSingleton().initialiseAllResourceGroups()
self.viewport = self.renderWindow.addViewport( self.camera )
self.viewport.setBackgroundColour (ogre.ColourValue(0, 0, 0))
self.camera.setPosition (0, 0, 100)
self.camera.lookAt(0, 0, 0)
self.createScene()
self._createFrameListener()
def createScene(self):
# Make a light
light = self.sceneManager.createLight('MainLight')
#light.setType(ogre.Light.LT_DIRECTIONAL)
#light.setDirection( ogre.Vector3( 0, -1.0, 1.0) )
light.setPosition (10, 10, 10)
self.baseNode = self.sceneManager.getRootSceneNode().createChildSceneNode()
# create a plane
facings = [ogre.Vector3.NEGATIVE_UNIT_X, ogre.Vector3.UNIT_Z, ogre.Vector3.UNIT_X, ogre.Vector3.NEGATIVE_UNIT_Z]
for f in range(len(facings)):
facing = facings[f]
plane = ogre.Plane()
plane.normal = facing
plane.d = 100
ogre.MeshManager.getSingleton().createPlane( "__thumbnailPlane__" +str(f), ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
plane, 80.0, 80.0, 1, 1, True, 1, 1.0, 1.0, ogre.Vector3.UNIT_Y )
planeEnt = self.sceneManager.createEntity( "LogoPlane"+str(f), "__thumbnailPlane__"+str(f))
planeEnt.setCastShadows( False )
planeEnt.setMaterialName( "Logo" )
# Create a node for it
n = self.baseNode.createChildSceneNode()
n.setPosition( facing * -100.0 )
n.attachObject( planeEnt )
def __del__(self):
"Clear variables, this should not actually be needed."
del self.camera
del self.sceneManager
del self.frameListener
del self.renderWindow
del self.root
def render(self):
return self.root.renderOneFrame()
def _createFrameListener(self):
self.frameListener = SimpleFrameListener(self.renderWindow, self.camera, self)
#self.frameListener.showDebugOverlay(True)
self.root.addFrameListener(self.frameListener)
class SimpleFrameListener(ogre.FrameListener, ogre.WindowEventListener, OIS.KeyListener):
def __init__(self, renderWindow, camera, app):
ogre.FrameListener.__init__(self)
ogre.WindowEventListener.__init__(self)
OIS.KeyListener.__init__(self)
self.camera = camera
self.renderWindow = renderWindow
self.toQuit = False
self.app = app
self.setupInput()
def setupInput(self):
windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW")
self.InputManager = OIS.createPythonInputSystem([("WINDOW",str(windowHnd))])
self.Keyboard = self.InputManager.createInputObjectKeyboard( OIS.OISKeyboard, False )
self.Mouse = self.InputManager.createInputObjectMouse( OIS.OISMouse, False )
self.windowResized(self.renderWindow)
self.Keyboard.setEventCallback(self)
ogre.WindowEventUtilities.addWindowEventListener(self.renderWindow, self)
def keyPressed(self, arg):
self.toQuit = True
def frameStarted(self, frameEvent):
if self.toQuit:
return False
self.Keyboard.capture()
self.Mouse.capture()
if self.Keyboard.isKeyDown(OIS.KC_ESCAPE):
return False
ms = self.Mouse.getMouseState()
if ms.X.rel or ms.Y.rel:
return False
self.app.baseNode.yaw(ogre.Degree(30.0) * frameEvent.timeSinceLastFrame )
return True
def __del__(self):
ogre.WindowEventUtilities.removeWindowEventListener(self.renderWindow, self)
self.windowClosed(self.renderWindow)
def windowClosed(self, rw):
#Only close for window that created OIS (mWindow)
if( rw == self.renderWindow ):
if( self.InputManager ):
self.InputManager.destroyInputObjectMouse( self.Mouse )
self.InputManager.destroyInputObjectKeyboard( self.Keyboard )
if self.Joy:
self.InputManager.destroyInputObjectJoyStick( self.Joy )
OIS.InputManager.destroyInputSystem(self.InputManager)
self.InputManager=None
def windowResized (self, rw):
[width, height, depth, left, top] = rw.getMetrics() # Note the wrapped function as default needs unsigned int's
ms = self.Mouse.getMouseState()
ms.width = width
ms.height = height
app = ApplicationFramework()
while app.render():
pass
This problem only seems to occur when a compiled exe is produced, I'll update the drivers for my gfx card (NV Geforce 8800 GT) now and see if that solves the issue.