[SOLVED] "Assertion failed, expression: pageloader"


07-11-2007 18:55:08

Hi, all!

Last week I wrote a post about some problems I had found when trying to write a simple PagedGeometry program following the examples from Tutorial 1. Well, after some cleaning, I managed to find where lied the problems in the code and fixed them. This Monday I managed to make the code work in Release Mode, and so far I haven't had any problems with it. Nevertheless, I can't execute this same code in Debug Mode, whenever I try the application crashes, and a dialog box pops up indicating an assertion failed pageLoader error. Ogre log does not register any exception, and using the debugger I have found that the application crashes at this instruction:

treeLoader->addTree(myEntity, position, yaw, scale);

Here you have the full code. I'm using the Example Framework, using the header and source files automatically generated by the AppWizard. I have the OgreSDK installed, and I'm running on VC++ 2005 Express. I get the exact same error both on OpenGL and Direct3d.

#ifndef __PGTut01_h_
#define __PGTut01_h_

#include "ExampleApplication.h"
#include "../res/resource.h"

#include <PagedGeometry.h>
#include "BatchPage.h"
#include "ImpostorPage.h"
#include "TreeLoader3D.h"

class PGTut01FrameListener : public ExampleFrameListener
SceneManager* mSceneMgr;
PagedGeometry* trees;
PGTut01FrameListener(SceneManager *sceneMgr, RenderWindow* win, Camera* cam, PagedGeometry* tree)
: ExampleFrameListener(win, cam),

bool frameStarted(const FrameEvent& evt)
bool ret = ExampleFrameListener::frameStarted(evt);

return ret;



class PGTut01App : public ExampleApplication
PagedGeometry *trees;




virtual void chooseSceneManager(void)
mSceneMgr = mRoot->createSceneManager(ST_EXTERIOR_CLOSE, "Terrain_Mgr");

virtual void createCamera(void)
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");

// Position it at 500 in Z direction
// Look back along -Z

virtual void createViewports(void)
// Create one viewport, entire window
Viewport* vp = mWindow->addViewport(mCamera);
// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));

virtual bool configure(void)
// Show the configuration dialog and initialise the system
// You can skip this and use root.restoreConfig() to load configuration
// settings if you were sure there are valid ones saved in ogre.cfg
// If returned true, user clicked OK so initialise
// Here we choose to let the system create a default rendering window by passing 'true'
mWindow = mRoot->initialise(true);
// Let's add a nice window icon
HWND hwnd;
mWindow->getCustomAttribute("WINDOW", (void*)&hwnd);
LONG iconID = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_APPICON) );
SetClassLong( hwnd, GCL_HICON, iconID );
return true;
return false;

// Trasteado

// Just override the mandatory create scene method
virtual void createScene(void)

Light *light = mSceneMgr->createLight("Sun");
light->setDirection(Vector3(0.0f, -0.5f, 1.0f));
mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));

trees = new PagedGeometry();

trees->setPageSize(50); // Our pages have dimensions 50x50
trees->setInfinite(); // No boundaries forcing for our geometries, this is set by default.

trees->addDetailLevel<BatchPage>(150, 30); // Pages at 150 units from Camera selected will be drawn at full quality
// Second parameter is a "fade" length. It defines a transition from
// this detail level to the next one (in this case, the transition takes
// place at 150-180 range). Transitions hurt the performance.

trees->addDetailLevel<ImpostorPage>(400, 50); // This level of detail represents the page by means of a Billboard.
// Since it is the last LOD, the final transition will consist of
// Billboards fading into nothing.

//Create a new TreeLoader3D object first
TreeLoader3D *treeLoader = new TreeLoader3D(trees, TBounds(0, 0, 1500, 1500));
//And add a entity at the desired position/rotation/scale
Vector3 position(0,0,0);
Degree yaw(0);
Real scale(0);

Entity *myEntity = mSceneMgr->createEntity("Tree","tree2.mesh");

for (int i = 0; i < 20000; i++){
yaw = Degree(Math::RangeRandom(0, 360));

position.x = Math::RangeRandom(0, 1500);
position.z = Math::RangeRandom(0, 1500);
position.y = 0;

scale = Math::RangeRandom(0.5f, 0.6f);

treeLoader->addTree(myEntity, position, yaw, scale);


// treeLoader->addTree(myEntity, position, yaw, scale);



// Create new frame listener
void createFrameListener(void)
mFrameListener= new PGTut01FrameListener(mSceneMgr, mWindow, mCamera, trees);

void destroyScene(void)
//Delete the TreeLoader3D instance
delete trees->getPageLoader();

//Delete the PagedGeometry instance
delete trees;

#endif // #ifndef __PGTut01_h_

Also, here you have the last part of Ogre.log. There's no exception identified, but this way you can identify where it crashes. Should I upload the whole file better?

18:20:47: Parsing script Example.particle
18:20:47: Parsing script smoke.particle
18:20:47: Parsing script Compositor.overlay
18:20:47: Parsing script DP3.overlay
18:20:47: Parsing script Example-CubeMapping.overlay
18:20:47: Parsing script Example-DynTex.overlay
18:20:47: Parsing script Example-Water.overlay
18:20:47: Parsing script Shadows.overlay
18:20:47: Finished parsing scripts for resource group General
18:20:47: Parsing scripts for resource group Internal
18:20:47: Finished parsing scripts for resource group Internal
18:20:48: Mesh: Loading tree2.mesh.
18:20:48: WARNING: tree2.mesh is an older format ([MeshSerializer_v1.30]); you should upgrade it as soon as possible using the OgreMeshUpgrade tool.
18:20:48: Texture: wood7.jpg: Loading 1 faces(PF_R8G8B8,600x600x1) with 5 generated mipmaps from Image. Internal format is PF_X8R8G8B8,600x600x1.
18:20:48: Texture: Leaves.png: Loading 1 faces(PF_A8R8G8B8,64x64x1) with hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,64x64x1.

If anyone can offer any help, it will be really appreciated.

Thanks in advance.


08-11-2007 14:42:37

(Sorry I didn't reply sooner)

Thanks for posting this, I'll try that code out soon and see if I can reproduce + debug the problem. It would be helpful (but not necessary if I can reproduce the error myself) to know where in treeLoader->addTree() the assertion failure is occurring, but I don't know if your debugger can do that.


08-11-2007 17:32:44

Ok, I've found the problem. There's a minor bug in PagedGeometry where if you call treeLoader->addTree() before you call trees->setPageLoader(treeLoader), it will crash.

You can fix the problem by either moving trees->setPageLoader(treeLoader) before your calls to addTree(), or download the latest version of "PagedGeometry.cpp" from CVS (where the problem is fixed). I'll probably update the ZIP versions soon with this fix, but I'm going to wait for any other bug reports before "wasting" an entire .01 version increase on this minor bug :)


14-11-2007 11:06:03

Sorry for being so late to reply.

Just wanted to thank you for your help. As expected, everything went well as soon as I changed the order of the instructions.

If I happened to find any other problems that might potentially be bugs, I will post them ASAP

Thanks again :). Bye!


14-11-2007 15:48:28

Just wanted to thank you for your help. As expected, everything went well as soon as I changed the order of the instructions.
Good :). Also, if you download the latest version (1.02) you should be able to run your original code now without problems.

If I happened to find any other problems that might potentially be bugs, I will post them ASAP
Thanks :)