   std::vector problem (again)
  Heey all,Here's the problem. I'm a CMesh class for the vertices, triangles, normals, vertex colours and texture vertices. All are in a std::vector. I can create a mesh, give it some data and it renders just fine, but as soon as I destroy the mesh and the destructor of the std::vector is called, I'm getting a "Corrupt heap error". I know what this means (the accessed memory is not allocated or already freed). But the problem is that the vector has not done or already done this, so I can't influence it.I have this calling stack:I'm using Microsoft Visual C++ 2008 Express and wxWidgetsDoes anybody have a clue what I'm doing wrong?assainatorThis is the CMesh class definition and Triangle class definition#pragma once#define ENGINE_API __declspec(dllexport)//CEngine includes#include "Vec3.hpp"#include "Vertex3.hpp"#include "Triangle.hpp"//gl includes#include <windows.h>//include this to prevent gl.h from acting weird#include <gl/gl.h>//other includes#include <vector>class CMesh{public://datastd::vector<CVertex3> Vertices;std::vector<CTriangle> Triangles;std::vector<CVec3> Colors;std::vector<CVec3> Normals;std::vector<CVec3> TVertices;bool DoRender;//functionsENGINE_API void Render();//constructor & deconstructorENGINE_API CMesh(void) {}ENGINE_API~CMesh(void) {}};#pragma once#define ENGINE_API __declspec(dllexport)class CTriangle{public://dataunsigned int v1, v2, v3;unsigned int tv1, tv2, tv3;unsigned int normalIndex;ENGINE_API CTriangle(void);ENGINE_API CTriangle(unsigned int v1, unsigned int v2, unsigned int v3);ENGINE_API CTriangle(unsigned int v1, unsigned int v2, unsigned int v3, unsigned int tv1, unsigned int tv2, unsigned int tv3);ENGINE_API CTriangle(unsigned int v1, unsigned int v2, unsigned int v3, unsigned int tv1, unsigned int tv2, unsigned int tv3, unsigned int normalIndex);ENGINE_API ~CTriangle(void);};
  Heap corruption occurs when your application writes to memory that the runtime uses as bookkeeping information for memory allocations. Usually this means a non-kosher pointer error or a buffer overrun.   ;  O, I thought it was as I explained. Well, learned something new today! ;)assainator   ;Quote:Original post by SiCraneHeap corruption occurs when your application writes to memory that the runtime uses as bookkeeping information for memory allocations. Usually this means a non-kosher pointer error or a buffer overrun.Does this mean if you try and write off the end of a vector it will causes the program to exit, rather than just allow it to happen like it would with a normal array?;Quote:Does this mean if you try and write off the end of a vector it will causes the program to exitThat's undefined behavior. Not "exit" behavior.Quote:rather than just allow it to happen like it would with a normal arraySame as above.   ;  Your CTriangle class has a destructor, yet no copy-constructor or assignment operator. Assuming your destructor is necessary then you need to implement the other two as well. It's called the "rule of three" if you want to look it up.   ;  Thanks for the advice, I have updated my class but I'm still having the same errorTriangle.hpp#pragma once#define ENGINE_API __declspec(dllexport)class CTriangle{public://dataunsigned int v1, v2, v3;unsigned int tv1, tv2, tv3;unsigned int normalIndex;ENGINE_API CTriangle(void);ENGINE_API CTriangle(const CTriangle &t);ENGINE_API CTriangle(unsigned int v1, unsigned int v2, unsigned int v3);ENGINE_API CTriangle(unsigned int v1, unsigned int v2, unsigned int v3, unsigned int tv1, unsigned int tv2, unsigned int tv3);ENGINE_API CTriangle(unsigned int v1, unsigned int v2, unsigned int v3, unsigned int tv1, unsigned int tv2, unsigned int tv3, unsigned int normalIndex);ENGINE_API ~CTriangle(void);//operatorsENGINE_API CTriangle &operator=(const CTriangle &c);};Triangle.cpp#include "Triangle.hpp"CTriangle::CTriangle(const CTriangle &t){v1 = t.v1;v2 = t.v2;v3 = t.v3;tv1 = t.tv1;tv2 = t.tv2;tv3 = t.tv3;normalIndex = t.normalIndex;}CTriangle::CTriangle(void){v1 = v2 = v3 = 0;tv1 = tv2 = tv3 = 0;normalIndex = 0;}CTriangle::CTriangle(unsigned int nv1, unsigned int nv2, unsigned int nv3){v1 = nv1;v2 = nv2;v3 = nv3;tv1 = tv2 = tv3 = 0;normalIndex = 0;}CTriangle::CTriangle(unsigned int nv1, unsigned int nv2, unsigned int nv3, unsigned int ntv1, unsigned int ntv2, unsigned int ntv3){v1 = nv1;v2 = nv2;v3 = nv3;tv1 = ntv1;tv2 = ntv2;tv3 = ntv3;normalIndex = 0;}CTriangle::CTriangle(unsigned int nv1, unsigned int nv2, unsigned int nv3, unsigned int ntv1, unsigned int ntv2, unsigned int ntv3, unsigned int nnormalIndex){v1 = nv1;v2 = nv2;v3 = nv3;tv1 = ntv1;tv2 = ntv2;tv3 = ntv3;normalIndex = nnormalIndex;}CTriangle::~CTriangle(void){}inline CTriangle & CTriangle::operator=(const CTriangle &t){if(this != &t){v1 = t.v1;v2 = t.v2;v3 = t.v3;tv1 = t.tv1;tv2 = t.tv2;tv3 = t.tv3;normalIndex = t.normalIndex;}return *this;}