Access violation when setting GrassLayer attributes

PrdglSqrl

14-01-2008 18:35:47

Anytime I attempt to set a layers attribute, I get an Access violation.

When the error occurs, VC++ points to me the implementation of the function I tried calling. For instance, when I call layer->setMinimumSize(...), VC++ pops up grassloader.cpp and points to the first line in the function setMinimumSize(). Same for all the other functions of GrassLayer.

I don't know what would be causing this, I'm passing in appropriate values to the functions. 2 floats into setMinimumSize() for example.

The only thing that might be out of the ordinary is that I'm storing pointers to the layers in a map. (I want each layer to have a unique name)

class BillboardSeeder{
private:
PagedGeometry* seeder;
GrassLoader* loader;
//vector<bool> animated;
map<string, GrassLayer*> layers;
};


The map is used in most of the BillboardSeeder's functions to obtain the pointer for a particular GrassLayer object. Other than that, i don't see any difference in the way I use the library. They are created just as they should be using:
GrassLayer* layer = loader->addLayer(material_name);

JohnJ

14-01-2008 19:18:42

I don't think the problem could possibly be in the implementation of the functions, obviously:
void GrassLayer::setMinimumSize(float width, float height)
{
minWidth = width;
minHeight = height;
}


If you're getting an access violation calling this function, it's almost certainly due to a invalid pointer, and since the code itself isn't using any pointers, this means you must be calling setMinimumSize() for a GrassLayer that doesn't exist. I'd suggest you check that your "layer" variable contains a valid object in the VS Debugger just before you modify it's attributes. Chances are something went wrong with your std::map access code and it's returning an invalid / null layer pointer.