noorus
22-03-2011 14:05:05
Hi,
I'm trying to finally actually get our project to use portals. We've had the PCZSM on the background for a good while but haven't actually utilised it, just had everything in the default zone.
We have outdoors terrain of Ogre::Terrain chunks next to each other, and each of these is one game-defined Zone. So I'm trying to get started by making each game-zone an PCZone, this is the code:
With this done, the game crashes on the first frame render, with a callstack like:
The crash happens here:
Any help? It's really quite difficult to gather all the bits and pieces of things to do and remember in order to use PCZSM
I'm trying to finally actually get our project to use portals. We've had the PCZSM on the background for a good while but haven't actually utilised it, just had everything in the default zone.
We have outdoors terrain of Ogre::Terrain chunks next to each other, and each of these is one game-defined Zone. So I'm trying to get started by making each game-zone an PCZone, this is the code:
Zone::Zone( Engine* pEngine, World* pWorld, const Vector3& vecPosition,
const std::wstring& sTerrainFilename, const Ogre::String& sName ):
mEngine( pEngine ), mWorld( pWorld ), mName( sName ), mZone( NULL ),
mNode( NULL ), mPortalInto( NULL ), mPortalOutFrom( NULL ),
mPosition( vecPosition )
{
mTerrain = new GameTerrain( sTerrainFilename, mPosition,
mEngine->pPhysics, mWorld->getPhysical(), mEngine->pGraphics,
this );
initialize();
}
void Zone::initialize( void )
{
PCZSceneManager* mScene = mEngine->pGraphics->getSceneMgr();
PCZSceneNode* mBaseNode = (PCZSceneNode*)mScene->getRootSceneNode();
mNode = (PCZSceneNode*)mBaseNode->createChildSceneNode(
mName + "_node", mPosition );
// Create zone
mZone = mScene->createZone( "ZoneType_Default", mName + "_zone" );
mZone->setEnclosureNode( mNode );
mScene->addPCZSceneNode( mNode, mZone );
float fRadius = mTerrain->getWorldSize() / 2.0f;
Vector3 vaCorners[2];
vaCorners[0] = Vector3( -fRadius, 0.0f, -fRadius );
vaCorners[1] = Vector3( fRadius, mTerrain->getWorldSize(), fRadius );
// Create AABB portal encompassing this terrain piece
mPortalInto = mScene->createPortal( mName + "_portalInto",
Ogre::PortalBase::PORTAL_TYPE_AABB );
mPortalInto->setCorners( vaCorners );
mPortalInto->setDirection( Vector3::UNIT_Z ); // portal normals point outwards
mPortalInto->setNode( mNode );
mPortalInto->setTargetZone( mZone );
mPortalInto->updateDerivedValues();
mZone->_addPortal( mPortalInto );
// Create AABB portal encompassing this terrain piece
mPortalOutFrom = mScene->createPortal( mName + "_portalOutFrom",
Ogre::PortalBase::PORTAL_TYPE_AABB );
mPortalOutFrom->setCorners( vaCorners );
mPortalOutFrom->setDirection( Vector3::NEGATIVE_UNIT_Z ); // portal normals point inwards
mPortalOutFrom->setNode( mNode );
mPortalOutFrom->setTargetZone( mZone );
mPortalOutFrom->updateDerivedValues();
mZone->_addPortal( mPortalOutFrom );
}
void Zone::activatePhysical( void )
{
mTerrain->activatePhysical();
}
void Zone::activateVisual( void )
{
mTerrain->activateVisual();
}
void Zone::deActivatePhysical( void )
{
mTerrain->deActivatePhysical();
}
void Zone::deActivateVisual( void )
{
mTerrain->deActivateVisual();
}
Zone::~Zone()
{
PCZSceneManager* mScene = mEngine->pGraphics->getSceneMgr();
if ( mPortalOutFrom )
mScene->destroyPortal( mPortalOutFrom );
if ( mPortalInto )
mScene->destroyPortal( mPortalInto );
if ( mZone )
mScene->destroyZone( mZone, false );
if ( mNode )
mScene->destroySceneNode( mNode->getName() );
SAFE_DELETE( mTerrain );
}
With this done, the game crashes on the first frame render, with a callstack like:
> Plugin_PCZSceneManager_d.dll!Ogre::PCZSceneNode::_addToRenderQueue(Ogre::Camera * cam=0x0283a960, Ogre::RenderQueue * queue=0x05b82ed0, bool onlyShadowCasters=false, Ogre::VisibleObjectsBoundsInfo * visibleBounds=0x05d9ec40)
Plugin_PCZSceneManager_d.dll!Ogre::PCZSceneManager::_findVisibleObjects(Ogre::Camera * cam=0x0283a960, Ogre::VisibleObjectsBoundsInfo * visibleBounds=0x05d9ec40, bool onlyShadowCasters=false)
OgreMain_d.dll!Ogre::SceneManager::_renderScene(Ogre::Camera * camera=0x0283a960, Ogre::Viewport * vp=0x0283b570, bool includeOverlays=true)
Plugin_PCZSceneManager_d.dll!Ogre::PCZSceneManager::_renderScene(Ogre::Camera * cam=0x0283a960, Ogre::Viewport * vp=0x0283b570, bool includeOverlays=true)
OgreMain_d.dll!Ogre::Camera::_renderScene(Ogre::Viewport * vp=0x0283b570, bool includeOverlays=true)
OgreMain_d.dll!Ogre::Viewport::update()
OgreMain_d.dll!Ogre::RenderTarget::_updateViewport(Ogre::Viewport * viewport=0x0283b570, bool updateStatistics=true)
RenderSystem_Direct3D9_d.dll!Ogre::D3D9RenderWindow::_updateViewport(Ogre::Viewport * viewport=0x0283b570, bool updateStatistics=true)
OgreMain_d.dll!Ogre::RenderTarget::_updateAutoUpdatedViewports(bool updateStatistics=true)
OgreMain_d.dll!Ogre::RenderTarget::updateImpl()
OgreMain_d.dll!Ogre::RenderTarget::update(bool swap=false)
OgreMain_d.dll!Ogre::RenderSystem::_updateAllRenderTargets(bool swapBuffers=false)
OgreMain_d.dll!Ogre::Root::_updateAllRenderTargets(Ogre::FrameEvent & evt={...})
OgreMain_d.dll!Ogre::Root::renderOneFrame(float timeSinceLastFrame=6.8937351e-007)
The crash happens here:
void PCZSceneNode::_addToRenderQueue( Camera* cam,
RenderQueue *queue,
bool onlyShadowCasters,
VisibleObjectsBoundsInfo* visibleBounds )
{
ObjectMap::iterator mit = mObjectsByName.begin(); // <---- boom! access violation. either thisptr is invalid, or mObjectsByName is zero. i can't really tell.
Any help? It's really quite difficult to gather all the bits and pieces of things to do and remember in order to use PCZSM
![Sad :(]({SMILIES_PATH}/icon_sad.gif)