A weird SIGTRAP error appears in a C++ OpenGL program of mine. First, a float array with the new[] operator is created like so:
std::vector<ObjFace> faces = readObjFile("sphere.obj");
vertexBufferSize = faces.size() * 24;
auto* vertexBuffer = new GLfloat[vertexBufferSize];
Then, the array is filled like this:
for (int i{ 0 }; i < faces.size(); ++i) {
for (int j{ 0 }; j < 4; ++j) {
vertexBuffer[i*24 + j*8] = faces[i].corners[j][0];
vertexBuffer[i*24 + j*8 + 1] = faces[i].corners[j][1];
vertexBuffer[i*24 + j*8 + 2] = faces[i].corners[j][2];
vertexBuffer[i*24 + j*8 + 3] = 1.0f;
vertexBuffer[i*24 + j*8 + 4] = (faces[i].normals[j][0] + 1) / 2;
vertexBuffer[i*24 + j*8 + 5] = (faces[i].normals[j][1] + 1) / 2;
vertexBuffer[i*24 + j*8 + 6] = (faces[i].normals[j][2] + 1) / 2;
vertexBuffer[i*24 + j*8 + 7] = 1.0f;
}
}
And it is then used with the glBufferData Macro and deleted afterwards:
glBufferData(GL_ARRAY_BUFFER, vertexBufferSize * sizeof(GLfloat), vertexBuffer, GL_STATIC_DRAW);
delete[] vertexBuffer;
vertexBuffer = nullptr;
For some reason the program will sometimes crash on a SIGTRAP error (debug mode) or with exit code -1073740940 (0xC0000374) (regular execution). I also made sure that vertexBuffer is not a nullpointer.
This problem only occurrs if the array size is relatively small. For bigger sizes, it works without a problem. To get it working with smaller sizes, I must not use new[] and delete[] - but then it will crash on bigger arrays because they take up too much space. Can someone explain to me what is going on here?