I'm using Qt5.1 compiled for Visual Studio 2008.
I'm trying to render objects with multiple textures. In my original code, I use a mesh class to manage loading 3D objects, which is based on this tutorial:
http://ogldev.atspace.co.uk/www/tutorial22/tutorial22.html
The mesh class contains a vector that holds textures. Textures load image data from files and keep track of all of the OpenGL state housekeeping necessary to render themselves.
I get a "Debug assertion failed: _BLOCK_TYPE_US_VALID(pHead->nBlockUse)" error when trying to use Qt to add more than one texture to my mesh class vector container. This error occurs when the destructor is called when adding textures to the vector, similar to what is described in this thread:
Destructor called on object when adding it to std::list
I am new to Qt and am wondering what the best way to handle textures is in this case. The tutorial code uses GLEW rather than Qt and I had to inherit from the QOpenGLFunctions to manage the OpenGL state for rendering the textures (my mesh class also inherits from QOpenGLFunctions). It appears that the default copy constructor is doing a shallow copy of the texture object, which deletes memory that is managed by Qt. However, when I switch to using a list container for textures, I don't get the assertion error.
Here is a simplification of my code that illustrates my problem:
#include <QOpenGLFunctions_3_3_Core>
#include <list>
#include <vector>
class Texture : protected QOpenGLFunctions_3_3_Core
{
public:
Texture()
{
}
~Texture()
{
std::cout << "destructor" << std::endl;
}
};
std::vector<Texture> textureList; //this causes the assertion failure
//std::list<Texture> textureList; //this works
void tester()
{
for (int i = 0; i < 3; i++)
{
Texture Texture;
textureList.push_back(Texture);
}
}
int main()
{
tester();
//Qt application code
}