Original Post
Hello, since a few days I'm going deeper into 3D game programming. Now I'm working on a primitive OpenGL graphics api. But I got a problem with my interfaces for it. Here is the render method that crashes in the second loop:
//
// Renders the objects in this scene.
//
long Scene::renderSceneObjects()
{
long objectsRendered = 0;
std::list<IRenderObject*>::iterator itObject = renderObjects.begin();
for (; itObject != renderObjects.end(); itObject++) {
IRenderObject* renderObject = (*itObject);
long verticesCount = 0;
IComplexVertex* vertices = renderObject->getVertices(&verticesCount);
if ((vertices) && (verticesCount > 0)) {
glBegin(renderObject->getRenderType());
for (long i = 0; i < verticesCount; i++) {
glVertex3f(vertices.getX(),
vertices.getY(),
vertices.getZ());
}
glEnd();
}
}
return 1;
}
The problem happens when adding the second vertex to the render process. In the debugger I see that the method calls are going weird. And this is the method that creates the vertex array:
//
// Returns an array with all vertices in this object.
//
IComplexVertex* RenderObject::getVertices(long* count)
{
// Get number of vertices defined in this object
const long vertexCount = getVertexCount();
// Allocate memory
ComplexVertex* cv = NULL;
try {
if ((cv = new ComplexVertex[vertexCount]) == NULL)
throw std::bad_alloc();
}
catch (...) {
//! @TODO Add error to logfile !!
return NULL;
}
// Iterate vertex positions
long index = 0;
list<IComplexVertex*>::iterator it;
for (it = vertices.begin(); it != vertices.end(); it++) {
IComplexVertex* cvertex = (*it);
cv[index++].setPos(cvertex);
}
// Update count variable to match vertices count
if (count) {
(*count) = vertexCount;
}
return cv;
}
Can anyone tell me how I can fix this ?? I've tried several things, but nothing helps.