Question

I have a vector, defined by std::vector<LPDIRECT3DTEXTURE9> textures; Later, I am passing a LPDIRECT3DTEXTURE9 object to it, like so textures.push_back(texture); Here is a sample of this:

void SpriteManager::AddSprite(float x, float y, float z, LPDIRECT3DTEXTURE9 texture)
{
    //snip
    textures.push_back(texture);
    //snip
}

This is causing a runtime error. It is breaking in the vector class at the size() function. Why might this happen?

Edit:

I also run into an identical problem performing the same operation on a vector of D3DXVECTOR3 objects. Since LPDIRECT3DTEXTURE9 is a pointer to an IDIRECT3DTEXTURE9, should I be using that instead?

Was it helpful?

Solution

By far the most common reason is that you actually don't have a vector. In this case, textures appears to be a member of the SpriteManager class. So, that suggest you actually don't have a SpriteManager object either. Is the this pointer valid?

OTHER TIPS

Well, since LPDIRECT3DTEXTURE9 by its Hungarian name is a pointer and not an object (as you refer to it), my guess is that you are passing around invalid pointers which have already done a fandango on your poor vector object before you call push_back().

I might be wrong, but this is as much as can be said from the information you provide. And, yes, push_back() should only be able to fail if you are out of memory or trying to use a non-copyable or non-assignable object in the vector, and then not through an access violation.

Your vector has been corrupted. I'd suggest putting a data watchpoint on its internals to see what is stomping on it (in a debugger).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top