strange error

land

13-03-2008 16:08:42

hello, everyone~

I followed the basic tutorial 2, the code is like this:

import ogre.renderer.OGRE as ogre
import SampleFramework as sf


class TutorialApplication (sf.Application):

def _createScene (self):
pass

def _createCamera (self):
pass

def _createViewports (self):
pass


if __name__ == '__main__':
ta = TutorialApplication ()
ta.go ()

when running the code, after the ogre dialog showing, the error show up:

Traceback (most recent call last):
File "/home/username/workspace/test/src/basic_2.py", line 22, in <module>
ta.go ()
File "/home/username/python_ogre/development/root/usr/lib/python2.5/site-packages/ogre/renderer/OGRE/sf_OIS.py", line 65, in go
self.root.startRendering()
File "/home/username/python_ogre/development/root/usr/lib/python2.5/site-packages/ogre/renderer/OGRE/sf_OIS.py", line 309, in frameStarted
self._moveCamera()
File "/home/username/python_ogre/development/root/usr/lib/python2.5/site-packages/ogre/renderer/OGRE/sf_OIS.py", line 436, in _moveCamera
self.camera.yaw(self.rotationX)
AttributeError: 'NoneType' object has no attribute 'yaw'
Unregistering ResourceManager for type BspLevel
*-*-* OGRE Shutdown

But I tried to type some code to replace the "pass"in the "def _createCamera (self)" section, the program was ok to run. Like this:


def _createCamera (self):
self.camera = self.sceneManager.createCamera ('PlayerCam')
self.camera.position = (0, 150, -500)
self.camera.lookAt ((0, 0, 0))
self.camera.nearClipDistance = 5

Could anyone explain that? Thanks.

my development enviroment:
OS: Ubuntu 7.10
IDE: eclipse
The python-ogre svn source code was downloaded and compiled about 2 weeks ago.

scriptkid

13-03-2008 19:17:11

Even though Tutorial 2 seems to do the same, i am not sure at which instance your camera gets created. If you say 'self.camera', then i'd guess that 'self' is your TutorialApplication, and not the sf.Application.

So, in 'self.camera.yaw', 'self' is sf.Application, which doesn't have a camera. Or does Python look both up and down the class chain ways when looking up variables?

Maybe you can try:

def _createCamera:
sf.Application.camera = self.sceneManager.createCamera ('PlayerCam')

Some python guru please correct me if i'm wrong :)

bharling

13-03-2008 21:22:55

No sorry have to correct ye there!,

if you inherit the SampleFramework.Application, then 'self' is both your TutorialApplication AND SampleFramework.Application.

if you define

def _createCamera(self):
pass


you are overriding the _createCamera method that is already defined in SampleFramework.Application, and essentially telling it to do nothing ( pass ), instead of creating a camera. Then when the frameListener in sf comes along, its expecting a camera that has not been created. That is why you get the error. There are 2 ways round this, one of which you've already done and it worked, the other would just be to delete the _createCamera function in TutorialApplication, that way it will just use the version that is already defined by the sampleframework.

What you aren't seeing in the TutorialApplication is the __init__ function, which looks something like this:

class TutorialApplication( sf.Application ):
def __init__(self):
sf.Application.__init__(self)


This is kind of taken care of for you, so you dont actually need to add this to your code. Basically this says,

'I'm making an object called TutorialApplication, which is exactly the same as sf.Application, but I might want to change / add a few bits myself. Anything that I don't explicitly change myself, assume that its the same as sf.Application'.

Hope that helps :).

land

14-03-2008 14:48:30

Oh, I see, thanks!