[SOLVED] Weird crash with GrassLoader::addLayer()

PrdglSqrl

11-01-2008 21:42:09

For my project, I decided to wrap up the GrassLoader in a nice, even easier to use class. One that would reduce the configuration down to 2 to 3 function calls.

Here's the layout for the class as is in my .h file for it:

class BillboardSeeder{
private:
PagedGeometry* seeder;
GrassLoader* loader;

public:
BillboardSeeder();
BillboardSeeder(YEI3D* app, float pageSize, float cullDist);
~BillboardSeeder();
void init(YEI3D* app, float pageSize, float cullDist);
void destroy();
void update();
void reload();

GrassLayer* addLayer(string mname);

GrassLayer* addLayer(string mname, float minw, float minh, float maxw, float maxh, float density,
FadeTechnique fadeTech, bool animated=true, float swaydist=1.0, float swaylen=1.0, float swayspd=1.0);

void configureLayer(GrassLayer* layer, float minw, float minh, float maxw, float maxh, float density,
FadeTechnique fadeTech, bool animated=true, float swaydist=1.0, float swaylen=1.0, float swayspd=1.0);


Simple...

Here's where it crashes:

GrassLayer* BillboardSeeder::addLayer(string mname){
GrassLayer* layer = loader->addLayer(mname); // This is line it crashes on!
return layer;
}


The crash dialog says:
File: /blah/blah/blah/.../ogresharedptr.h
Line: 134
Expression: pRep

I have no clue what this really means, but I'm assuming since the file is ogresharedptr.h, that it has something to do with the layer variable in addLayer().

Any thoughts?

JohnJ

12-01-2008 00:40:13

Like you say the error is pretty vague so it's hard to tell what the error is without using debug mode to check what line it's crashing on, but I'd guess that there is no loaded Material with the name of "mname", which results in a null SharedPtr when trying to apply the material to the grass. Try putting a breakpoint on your line where addLayer() is called, and make sure "mname" is a valid material name.

PrdglSqrl

14-01-2008 17:44:48

You know your stuff! That's exactly what was wrong. lol

The material's name is grass. But instead of just "grass", I passed in "grass.material".

Thanks a million.

JohnJ

14-01-2008 18:32:07

Ok, glad I could help.

BTW, in the next version (currently scheduled for release this Saturday), the grass system will no longer give such an undescriptive error for this problem. When an invalid material name is given, it will tell you so. I'm sure this will eliminate a lot of confusion since this error (invalid material) isn't very uncommon :)