[BUG??] tileLoaded in PLSM2

_Archic

10-07-2006 16:10:15

Hi!

May I can find some bug or use PLSM2 incorrectly?

I download OgreSDK_PLSM2_source.zip (2770428 bytes) without problems have unpacked this archive, and have successfully builded Plugin_PagingLandScapeSceneManager2_d.dll (1929216 bytes) in Debug Mode by means of MS VS 2005 8.0.50727.42. After that has added it in Plugins.cfg, Has started MapSplitter.exe.

After that has written the test application. All works perfectly. I can see and wander on PLSM2 Terrain.

After that I have decided to connect OgreNewt, and for this purpose have added tileLoaded as it is described in Wiki (http://www.ogre3d.org/wiki/index.php/Us ... ith_Newton). I also have replaced all ocurrences SceneManager * on PagingLandScapeSceneManager*

After that at attempt of a call getPage (uint, uint) at PagingLandScapePageManager.
I receive exception "Unhandled exception at 0x00825bd1 in Phys.exe: 0xC0000005: Access violation reading location 0x76e90038".

It is similar on NullException, and PagingLandScapePageManager is not initialized. I was passed by a debugger in getPage and have found out, that exception arises by a call of function isCoord (at unary AND).

It is bug or I have written it somewhere incorrectly?


You can try to copy/paste this source and try it on your comp..

Help! :(


#pragma once
#include <ExampleApplication.h>
#include "OgrePagingLandScapeOptions.h"
#include "OgrePagingLandScapeCamera.h"
#include "OgrePagingLandScapePageManager.h"
#include "OgrePagingLandScapeListenerManager.h"
#include "OgrePagingLandScapeSceneManager.h"

using namespace Ogre;

class PLSM2Manager
{
PagingLandScapeSceneManager* m_sceneManager;
public:

PLSM2Manager(PagingLandScapeSceneManager* sceneManager, Camera * mCamera):m_sceneManager(sceneManager)
{
PagingLandscapeDelegate * loadTileDelegate = new PagingLandscapeDelegate();
loadTileDelegate->bind(this,&PLSM2Manager::tileLoaded);
m_sceneManager->setOption("addLoadTileListener",loadTileDelegate);

m_sceneManager->setOption("LoadNow", mCamera);
}


void tileLoaded(PagingLandscapeEvent* e)
{
int pageX = e->mPagex;
int pageZ = e->mPagez;

PagingLandScapePageManager * pmgr = m_sceneManager->getPageManager();
PagingLandScapePage* page = pmgr->getPage(pageX, pageZ,false);//EXCEPTION HERE!
}
};

class MyApplication : public ExampleApplication
{
protected:
void createFrameListener()
{
mFrameListener = new ExampleFrameListener( mWindow, mCamera );
mRoot->addFrameListener(mFrameListener);
}

void createScene()
{
plsm2Manager = new PLSM2Manager(mSceneMgr,mCamera);
}

void chooseSceneManager()
{
mSceneMgr = (PagingLandScapeSceneManager*)mRoot->createSceneManager("PagingLandScapeSceneManager", "" );
mSceneMgr->setWorldGeometry( Ogre::String("paginglandscape2.cfg") );
}

private:
PLSM2Manager *plsm2Manager;
};

HexiDave

10-07-2006 16:20:56

The thing I notice and guess you missed in the other thread was to make your own PagingLandScapePageManager when you first create your PLSM2Manager, like this:

PLSM2Manager(PagingLandScapeSceneManager* sceneManager, Camera * mCamera):m_sceneManager(sceneManager)
{

mPageMgr = m_sceneManager->getPageManager(); // <-- here

PagingLandscapeDelegate * loadTileDelegate = new PagingLandscapeDelegate();
loadTileDelegate->bind(this,&PLSM2Manager::tileLoaded);
m_sceneManager->setOption("addLoadTileListener",loadTileDelegate);

m_sceneManager->setOption("LoadNow", mCamera);
}


And create PagingLandScapePageManager* mPageMgr with plsm2Manager:
PLSM2Manager *plsm2Manager;
PagingLandScapePageManager* mPageMgr;


Now call mPageMgr->getPage() instead of creating a new PagingLandScapePageManager* each time the delegate loads in tileLoaded().

_Archic

10-07-2006 18:51:25


Now call mPageMgr->getPage() instead of creating a new PagingLandScapePageManager* each time the delegate loads in tileLoaded().


Great thanx, HexiDave for your help, but nothing has changed behind that exception, that now the mistake arises at the first call on mPageMgr-> getPage().. :?


This source code works by your comp without problems? I can send Visual Studio Solution (*.sln) source codes that you could check up it by your comp..

At me the sensation starts to develop, that only you, HexiDave, really use PLSM2.. The Others only speak, that it is cool :)

HexiDave

10-07-2006 19:11:42

I'll create a new project here and copy your code from the other thread and try it out.

Also, there are quite a few people that use PLSM2, they just have more involved projects and usually tear through PLSM2's inner-workings early on, so can pin-point their problems. Also Tuan is on holidy for now, so he's taking a break from it (well deserved!)

I just have to create a terrain for my demo app and then I'll get testing for ya. I know how frustrating this problem was to track down.

HexiDave

10-07-2006 22:23:23

Well that's interesting - I copied the code from the other thread exactly as it was and it worked correctly. I ran it in release mode and it worked fine - it created all the tiles and all the collision data correctly.

Can you post your config file for the map you're using?

_Archic

11-07-2006 13:00:46

Well that's interesting - I copied the code from the other thread exactly as it was and it worked correctly. I ran it in release mode and it worked fine - it created all the tiles and all the collision data correctly.

Can you post your config file for the map you're using?


I suspected, that a mistake not in my source codes, and somewhere in other place :-)

I use standard Terrain which go together with MapSplitter.exe. It seems to me, that a mistake somewhere in plugin PLSM2. What size of a file at Plugin_PagingLandScapeSceneManager2_d.dll (My 1929216 bytes)

I have resulted the some cfg files.. If are required still any, list them please..

paginglandscape2.cfg

DefaultMap=terragen16bits

TerrainScene=TsmTerrain
puget_sound=ps_height_1k
grand_canyon=gcanyon_height_4k2k
terragen_genrated=terragen16bits
European_Alpes=Alpes
HorizonTestMap=hf_129_3
MyMap=MyMap
test=test

# resource group name where to find map definition
GroupName=PLSM2

# Try forbidden textureformat combinations
TextureFormatDebug=no


Plugins.cfg

# Defines plugins to load

# Define plugin folder
PluginFolder=.

# Define plugins
Plugin=RenderSystem_Direct3D9
Plugin=RenderSystem_GL
Plugin=Plugin_ParticleFX
Plugin=Plugin_BSPSceneManager
Plugin=Plugin_OctreeSceneManager
Plugin=Plugin_CgProgramManager
Plugin=Plugin_PagingLandScapeSceneManager2_d

Lythaniel

14-07-2006 10:16:20

Hi _Archic,


I'm currently trying to do exactly the same thing than you so I copied your code. I'm getting the same error. It was the same with all the maps I tried.

I'm quite new with OGRE and PLSM2 so I have no idea where could be the error but if i find something or if I find a workaround I will let you know.

Lyth

Lythaniel

14-07-2006 17:55:26

Hi _Archic,

I've made more investigation by tracking when the context of the scene manager was lost. I've come to the conclusion that the problem appears when casting the scene manager from a SceneManager class to a PagingLandScapeSceneManager class.

For that I have checked the physical adresse of the PageManager inside the object.


void PLSM2Manager::SetSceneManager(Ogre::SceneManager * _ScnMgr)
{

m_SceneManager = (PagingLandScapeSceneManager *) (_ScnMgr);


}


If you look at the physical adresse of the PageManager object in _ScnMgr i get 0x0c905890 but the same object in m_SceneManger is located at 0x06992d98.

I made something really ugly and just initialised the PageManager pointer with the direct value and it works fine (well I don't get collision detection with the ground but that's another problem).

I tried with a dynamic_cast but result is the same.

from my understanding, PagingLandScapeSceneManager derivate from PagingLandScapeOctreeSceneManager which derivate from the base class SceneManager, So i don't understand why the cast is not working properly. From my knowledge about polymorphism it should work but perhaps I'm mistaken.

Could it be also librairy problems (incompatibility, not correctly generated, link option incorrect ?)


I hope it helps anyway.

Lyth

Falagard

14-07-2006 18:26:45

Don't know exactly what's going on, but generally Tuan codes everything so you should never be casting directly to a PagingLandscapeSceneManager anyhow. Everything should be accessible through the generic SceneManager->getOption and setOption interfaces. This is a design decision that Tuan has made and it means that unless you abide by this design decision you're asking for trouble.

Why do you need access to a page directly? If you need some specific functionality of a page, see if there's a getOption function that will do it for you, if not, request the functionality from Tuan to add it to getOption, or, add it yourself and submit a patch.

Most of those classes aren't even public, so you shouldn't be able to access them anyhow. I'm guessing that there's a library compatibility problem btw.

Lythaniel

15-07-2006 14:14:47

Hi Falagard,

You are right, it's not secure to cast object like that, so I reworked the code and merged it with the original code on Wiki to get the following:

PLSM2Manager:



PLSM2Manager::PLSM2Manager(Ogre::SceneManager* sceneManager)
{

m_SceneManager = sceneManager;

loadTileDelegate=new PagingLandscapeDelegate();
loadTileDelegate->bind(this,&PLSM2Manager::tileLoaded);
m_SceneManager->setOption("addLoadTileListener",loadTileDelegate);


unloadTileDelegate=new PagingLandscapeDelegate();
unloadTileDelegate->bind(this,&PLSM2Manager::tileUnloaded);
m_SceneManager->setOption("addUnloadTileListener",unloadTileDelegate);

}

PLSM2Manager::~PLSM2Manager(void)
{

m_SceneManager->setOption("removeLoadTileListener",loadTileDelegate);
m_SceneManager->setOption("removeUnloadTileListener",unloadTileDelegate);

if (loadTileDelegate)
delete loadTileDelegate;
if (unloadTileDelegate)
delete unloadTileDelegate;



}


void PLSM2Manager::tileLoaded(PagingLandscapeEvent* event)
{
//recover PLSM2's tile object
int pageX=event->mPagex;
int pageZ=event->mPagez;
unsigned int tileX=event->mTilex;
unsigned int tileZ=event->mTilez;



//ask reference to geometry to PLSM2
std::vector<void*> params;
int renderLevel=0;
params.push_back(&pageX);
params.push_back(&pageZ);
params.push_back(&tileX);
params.push_back(&tileZ);
params.push_back(&renderLevel);
m_SceneManager->getOption("PageGetTileVertexData_2",&params);

//recover data at the end of the vector and send it to our physics class for the next step
int* numVtx=((int*)params[5]);
Vector3* vertices=((Vector3*)params[6]);
IndexData* indexData=((IndexData*)params[7]);

String TileName = "page"+StringConverter::toString(pageX) +"-" + StringConverter::toString(pageZ) +"-tile"+StringConverter::toString(tileX)+"-"+StringConverter::toString(tileZ);

SceneNode *sn;
sn = m_SceneManager->getRootSceneNode()->createChildSceneNode (TileName);
sn->setPosition(event->mBbox.getCenter());

PhysicsManager::getSingleton().loadTerrainGeometry(sn,vertices,*numVtx,indexData, TileName);

//cleanup
delete[] vertices;
delete numVtx;
}

void PLSM2Manager::tileUnloaded(PagingLandscapeEvent* event)
{

//recover PLSM2's tile object
int pageX=event->mPagex;
int pageZ=event->mPagez;
int tileX=event->mTilex;
int tileZ=event->mTilez;

String TileName = "page"+StringConverter::toString(pageX) +"-" + StringConverter::toString(pageZ) +"-tile"+StringConverter::toString(tileX)+"-"+StringConverter::toString(tileZ);

m_SceneManager->getRootSceneNode()->removeAndDestroyChild (TileName);
PhysicsManager::getSingleton().UnloadTerrainGeometry (TileName);


}




and PhysicsManager:



PhysicsManager::PhysicsManager(OgreNewt::World * W)
{
m_World = W;
}

PhysicsManager::~PhysicsManager(void)
{
}

void PhysicsManager::loadTerrainGeometry(Ogre::SceneNode * tileNode, Ogre::Vector3* vertices, int numVertices, Ogre::IndexData* indexData, String TileName)
{

if(tilesBodies[TileName]==NULL)
{

OgreNewt::TreeCollisionSerializer* serializer=new OgreNewt::TreeCollisionSerializer();
OgreNewt::CollisionPrimitives::TreeCollision* collision;

if(!ResourceGroupManager::getSingleton().resourceExists("General",TileName + ".collision"))
{
collision = new OgreNewt::CollisionPrimitives::TreeCollision(m_World,numVertices,vertices,indexData,false);
serializer->exportTreeCollision(collision,"coldata\\" + TileName + ".collision");
}
else
{
collision=new OgreNewt::CollisionPrimitives::TreeCollision(m_World);
DataStreamPtr ptr = ResourceGroupManager::getSingleton().openResource(TileName + ".collision");
serializer->importTreeCollision(ptr,collision);
}

OgreNewt::Body* body = new OgreNewt::Body(m_World,collision);
body->attachToNode(tileNode);

tilesBodies[TileName]=body;

delete collision;
}

}

void PhysicsManager::UnloadTerrainGeometry(String TileName)
{
OgreNewt::Body *body = tilesBodies[TileName];
delete body;
tilesBodies[TileName]=NULL;
}




This works fine here.

Note that I had to patch OgreNewt as explain is this thread : http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=1445&sid=38e1c9985e57e7d1622a97ef423aaa78 to make the collisions work.

Thanks,

Lyth

sklug

15-08-2006 03:45:33

Dredging up a slightly old topic as I am having related problems. I traced through all these threads on the topic and have made the patch to ogreNewt, etc. The geometry seems to be loaded into newton (at least, it seralizes it out to disk), but my objects don't collide with the terrain, and attempting to press F3 (from the OgreNewt::BasicFrameListener) causes the program to crash, somewhere deep in Newton.dll. As far as I can tell, my code is nearly identical to the final solution posted here. Any ideas?

[edit] Well, I just updated from CVS and rebuilt with some of the latest ogreNewt changes. Now my objects collide with the landscape. However, pressing F3 still crashes the app. Is that normal?

Steve

HexiDave

15-08-2006 08:32:20

It's not Newton that's crashing so much as it's usually complaining about video memory being full - it re-creates a manual object (the lines), vertex to vertex of the TreeCollision... each frame ... then destroys it.

So, ya, it's normal :)

sklug

15-08-2006 23:53:44

Wow.. video memory full with just one 512x512 page? (my current map is only one page) on a 256MB 6800GT? I guess I stll need to get a better feeling for what sort of limits I have resource-wise. But I haven't even started adding game assets yet. And it runs out of memory with a few hundred thousand lines? Interesting. Thanks for the quick response!

Steve

HexiDave

16-08-2006 00:39:41

Oh wait, only one page? Usually after several pages at 512x resolution turning on the debug view of OgreNewt will do it, but I dunno about one page.

Hmm, try using the serialized tiles, one at a time, in another application - just import the serialized tile as a TreeCollision and view it to see if it comes up. If it still throws errors, then something is amiss.

sklug

16-08-2006 04:41:32

Ok... I did what you suggested, mostly. I simply only loaded tile 0,0 in my code. So only one tile was loaded from disk, and it still crashes on F3. But as I said, the collisions against the landscape actually seem to be working fine.

Steve

HexiDave

16-08-2006 05:58:30

Ok then something goofy is going on with the debugger :( Ask around on the OgreNewt forum - Walaber probably knows what's wrong.