Hello,

My code pasted below is receiving random segmentation faults. I am not sure I took the right approach for a dynamic sized buffer of Triangle objects(3 Vector3f(3 floats)). Any idea's would be greatly appreciated.

The fault happens at the first write after entering the loop but only happens in glx_base code off Nehe's OGL site. This class works flawless all day long in the console.

Code:int cMesh::BuildMesh(cMCNK *pMCNK) { sTriangle *thisTri = NULL; sObject *thisObj = NULL; sMCNK_Block MCNK = pMCNK->GetMCNK_Block(); char *buffer = NULL; buffer = new char[sizeof(sTriangle) * 256]; memset(buffer, '\0', sizeof(sTriangle) * 256); thisTri = (sTriangle*)buffer[0]; thisObj = new sObject;a memset(thisObj, '\0', sizeof(sObject)); thisObj->Triangle = thisTri; thisObj->numTriangles = 256; thisObj->pNext = NULL; mesh->Object = thisObj; std::cout << mesh->Object->numTriangles; int OffsetX = (MCNK.MCNK.position.X); int OffsetY = (MCNK.MCNK.position.Z); int OffsetZ = (MCNK.MCNK.position.Y); for(int y = 0; y < 8; y++) { for(int x = 0; x < 0; x++) { //First Vertex: Pos 1 thisTri->Vertex[0].X = ((OffsetX)+((x * 3.703703704))); thisTri->Vertex[0].Y = ((OffsetY)+pMCNK->GetNoLod(x,y)); thisTri->Vertex[0].Z = ((OffsetZ)+((y * 3.703703704))); //Second Vertex: Pos 2 thisTri->Vertex[1].X = ((OffsetX)+(((x + 1) * 3.703703704))); thisTri->Vertex[1].Y = ((OffsetY)+pMCNK->GetNoLod((x + 1), y)); thisTri->Vertex[1].Z = ((OffsetZ)+((y * 3.703703704))); //Third Vertex: Pos 10 thisTri->Vertex[2].X = ((OffsetX)+(((x + 0.5) * 3.703703704))); thisTri->Vertex[2].Y = ((OffsetY)+pMCNK->GetLod(x, y)); thisTri->Vertex[2].Z = ((OffsetZ)+(((y + 0.5) * 3.703703704))); thisTri = thisTri + sizeof(thisTri); //First Vertex: Pos 2 thisTri->Vertex[0].X = ((OffsetX)+(((x + 1) * 3.703703704))); thisTri->Vertex[0].Y = ((OffsetY)+pMCNK->GetNoLod((x + 1), y)); thisTri->Vertex[0].Z = ((OffsetZ)+((y * 3.703703704))); //Second Vertex: Pos 19 thisTri->Vertex[1].X = ((OffsetX)+(((x + 1) * 3.703703704))); thisTri->Vertex[1].Y = ((OffsetY)+pMCNK->GetNoLod((x+1), (y+1))); thisTri->Vertex[1].Z = ((OffsetZ)+(((y + 1) * 3.703703704))); //Third Vertex: Pos 10 thisTri->Vertex[2].X = ((OffsetX)+(((x + 0.5) * 3.703703704))); thisTri->Vertex[2].Y = ((OffsetY)+pMCNK->GetLod(x, y)); thisTri->Vertex[2].Z = ((OffsetZ)+(((y + 0.5) * 3.703703704))); thisTri = thisTri + sizeof(thisTri); //First Vertex: Pos 19 thisTri->Vertex[0].X = ((OffsetX)+(((x+1) * 3.703703704))); thisTri->Vertex[0].Y = ((OffsetY)+pMCNK->GetNoLod((x+1), (y+1))); thisTri->Vertex[0].Z = ((OffsetZ)+(((y+1) * 3.703703704))); //Second Vertex: Pos 18 thisTri->Vertex[1].X = ((OffsetX)+((x * 3.703703704))); thisTri->Vertex[1].Y = ((OffsetY)+pMCNK->GetNoLod(x, (y+1))); thisTri->Vertex[1].Z = ((OffsetZ)+(((y+1) * 3.703703704))); //Third Vertex: Pos 10 thisTri->Vertex[2].X = ((OffsetX)+(((x + 0.5) * 3.703703704))); thisTri->Vertex[2].Y = ((OffsetY)+pMCNK->GetLod(x, y)); thisTri->Vertex[2].Z = ((OffsetZ)+(((y + 0.5) * 3.703703704))); thisTri = thisTri + sizeof(thisTri); //First Vertex: Pos 1 thisTri->Vertex[0].X = ((OffsetX)+((x * 3.703703704))); thisTri->Vertex[0].Y = ((OffsetY)+pMCNK->GetNoLod(x, y)); thisTri->Vertex[0].Z = ((OffsetZ)+((y * 3.703703704))); //Second Vertex: Pos 18 thisTri->Vertex[1].X = ((OffsetX)+((x * 3.703703704))); thisTri->Vertex[1].Y = ((OffsetY)+pMCNK->GetNoLod(x, (y+1))); thisTri->Vertex[1].Z = ((OffsetZ)+(((y+1) * 3.703703704))); //Third Vertex: Pos 10 thisTri->Vertex[2].X = ((OffsetX)+(((x + 0.5) * 3.703703704))); thisTri->Vertex[2].Y = ((OffsetY)+pMCNK->GetLod(x, y)); thisTri->Vertex[2].Z = ((OffsetZ)+(((y + 0.5) * 3.703703704))); thisTri = thisTri + sizeof(thisTri); } } return 0; }