preloading all tiles

Grom

19-02-2007 20:43:41

I'm integrating PLSM2 with NxOgre, and I have a question. When a pageLoad event happens, do all the tiles on that page get loaded?

I'm asking because I have to save height data for each tile, and I want to store it for all of a page's tiles in one file (so a file per page), but I need to know that all tiles are loaded so I can determine proper offsets into the file.

So essentially, when does the "LoadTileListener" get called?

OvermindDL1

20-02-2007 16:21:28

There is a way to preload everything up front, just call the option with PreLoad I think it is (quick look in the source and you will see). Otherwise, LoadTile would work to build on the fly.

Grom

21-02-2007 19:13:13

well I set MaxPreloadedPages in the cfg file to 4, since i have page width / height of 4. Then I called mSceneMgr->setOption("LoadNow", NULL);, and this will work nicely I think.

However, I'm getting a crash when I try to use getOption to get the vertex data. This is all of my code for the tile load event.


size_t pageX=event->mPagex;
size_t pageZ=event->mPagez;
size_t tileX=event->mTilex;
size_t tileZ=event->mTilez;

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);
sceneMgr->getOption("PageGetTileVertexData_2",&params);

int* numVtx=((int*)params[5]);
Vector3* vertices=((Vector3*)params[6]);
IndexData* indexData=((IndexData*)params[7]);

if(indexData)
delete indexData;
if(vertices)
delete [] vertices;
if(numVtx)
delete numVtx;


it will cause a crash if I try to get all tiles. If I include something like "if(pageX==0&&pageZ==0..." to get a specific page/tile, then it works fine. But when I leave it open to get every tile, I get a crash (except for every once in a while, say 1 in 5, where it works without crashing.)

Grom

23-02-2007 22:03:03

Alright i updated everything, I'm using CVS OGRE 1.4 and PLSM2. I can load and see my terrain and all that.

I have a LoadTileListener. When I try to do the above code that simply uses "PageGetTileVertexData_2" to get the vertex data, it crashes on "delete [] vertices". It's almost as if the LoadTile event is getting called before the vertex data has been filled in... is that possible?



It even happens when I use the code from this page (without the newton stuff). It happens at the same place, delete [] vertices. And strangely, it only happens sometimes.



*EDIT*
I set it up so that it tries to get the tiles only after all of the tiles for a page have been loaded. In other words, it calls getOption for each tile once the entire page has loaded. I still get a crash on delete [] vertices, usually on the second tile attempted.

I cracked open OgrePagingLandScapeSceneManager.cpp and checked out getOption("PageGetTileVertexData_2". I added simple else statements at the end of if(tile) an if(rend) to log if either of those failed. Now, sometimes when I run my app it fails immediately on delete [] vertices. Sometimes, it loads up the immediate area, but if i move around it fails when a new page is loaded in. When it loads up but fails on a distant page, i get a "REND FAILED" error from what I added in OgrePagingLandScapeSceneManager.cpp.

I find it strange that the page in the wiki about integrating plsm2 with newton apparently works, but with the stuff i have it causes a crash. Does anyone have any advice about fixing this? I'm not going to give up until I find a resolution, but I've been working at this one thing for a long while now.

tuan kuranes

28-02-2007 15:30:49

Can you try without deleting Index Buffer, from PLSM2 code, I don't think PageGetTileVertexData_2 allocates space and copy it into that. Actually it seems to just give you actual index buffer pointer. (not to be deleted.)
//if(indexData)
// delete indexData;


(note that WIKI page doesn't delete "indexData", perhaps you can add a comment over there to make it clear it shouldn't be deleted.)

Grom

28-02-2007 19:19:49

ah, looking through your code I see that it does indeed just assign a pointer, and shouldn't be deleted.

Unfortunately, even without deleting the index buffer, it still causes a crash on delete [] vertices. When it crashes, it seems to do so on the second tile to be loaded. Why would it work on the first, and then crash on the second? And why would it only happen sometimes? (once in awhile it loads everything well)

Grom

05-03-2007 00:52:20

is anyone else working on a project with the PLSM2 that is successfully able to load the height data for the terrain in this manner?

nindim

05-03-2007 10:16:07

Just wondering, why is your MaxPreloadedPages set to 4?


well I set MaxPreloadedPages in the cfg file to 4, since i have page width / height of 4.


If your map is 4*4 as you state above shouldnt it be 16 to load all the pages? Forgive me if I'm missing something.

Grom

05-03-2007 21:18:50

yeah I noticed that a while back and fixed it, thanks for pointing that out though. Still, I cannot get the vertex data.

nindim

05-03-2007 21:48:38

Hey Grom, sorry to hijack your thread! Seems like you have done a bit of work regarding getting vertx points etc from terrain, have you experimented at all with exporting these vertices to a file useable in a 3d editor? I posted a thread about it so you could have a look at what i'm trying to do there if you're willing to help.

Grom

06-03-2007 05:56:17

no I haven't been able to load all the vertex data at all yet, I'm trying to integrate PLSM2 with NxOgre but I've been hung up for weeks on a random crash that happens when I try to get all the tiles.

EDIT:

FINALLY, I started again from scratch and it loads all the tiles succesfully. I apologize for my foolish begging for answers.

bleubleu

12-04-2007 19:39:56

I know its an old post. But I just ran into the same problem (i think).

To solve crashes when using PageGetTileVertexData_2, you have to make sure that PLSM2 and your application are both built in the same mode (debug/release).

The reason it that the std::vector class might be organized differently in memory in debug and release mode (struct alignment, optimizations, who knows...).

A easy way to detect this is to print the address of the vector and say, the first elem [0] in your app and in PLSM2. If they dont match, something is wrong and you will end up writing data to some random memory location.

Mat

Grom

12-04-2007 23:28:16

I wasn't even aware that it would be possible to not use runtime with runtime. I generally don't even mess with debug builds, because I just debug manually in the runtime version. (it probably isn't that smart, but it works for me)

Anyway thanks for your reply!

Baiame

16-04-2007 07:54:13

Alright i updated everything, I'm using CVS OGRE 1.4 and PLSM2. I can load and see my terrain and all that.
Sorry for going OT, but how are you doing that? I recall reading around here that PLSM2 just doesn't work with Eihort. Do I need to get a CVS version, or did you modify the code?