Jump to content
  • Advertisement
Sign in to follow this  
taytay

Realy weird problem

This topic is 2544 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am getting a really weird crash. Not related but I am doing this. I am generating a terrain but it is too big. I decided to split index buffer into smaller parts. In future I am planning to generate a more detailed version of these parts, and the parts clsoer to camera will be rendered using detailed versions. It was perfectly working while I was generating the whole index buffer at once, but now I have problems.

My application has two choices, generate world or load world. Generate world generates a random terrain and stores this in a file. Load map loads the terrain from the file.

Weird thing is it only crashes when I generating the world. It generates and saves the world correctly (as far as I know) but crashes on first glDrawElements that uses the new partial index buffers.

part of my generate world function


for(i=0; i<16; i++){
for(j=0; j<16; j++){
glGenBuffersARB(1, &partIB[j]);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, partIB[j]);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(unsigned int)*partIBSizes[j], partInd[j], GL_STATIC_DRAW_ARB);
fprintf(fout, "%d %d %d %d %d\n", i, j, partIBSizes[j], partIB[j], partInd[j][0]);
}
}
glGenBuffersARB(1, &vb);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vb);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(Vertex)*1022*1022*5, buf, GL_STATIC_DRAW_ARB);

memcpy(bufBig, buf, sizeof(Vertex)*1022*1022*5);

if(SAVE){
fwrite(buf, sizeof(Vertex)*1022*1022*5, 1, mapData);

for(i=0; i<16; i++){
for(j=0; j<16; j++){
fwrite(&partIBSizes[j], sizeof(unsigned int), 1, mapData);
fwrite(partInd[j], sizeof(unsigned int)*partIBSizes[j], 1, mapData);
}
}
}


and part of my load world function


fread(buf, sizeof(Vertex)*1022*1022*5, 1, mapData);


unsigned int *partInd = (unsigned int *)malloc(sizeof(unsigned int)*1024*1024);
for(int i=0; i<16; i++){
for(int j=0; j<16; j++){
fread(&partIBSizes[j], sizeof(unsigned int), 1, mapData);
fread(partInd, sizeof(unsigned int)*partIBSizes[j], 1, mapData);
glGenBuffersARB(1, &partIB[j]);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, partIB[j]);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(unsigned int)*partIBSizes[j], partInd, GL_STATIC_DRAW_ARB);
fprintf(fout, "%d %d %d %d %d\n", i, j, partIBSizes[j], partIB[j], partInd[0]);
}
}

free(partInd);

glGenBuffersARB(1, &vb);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vb);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(Vertex)*1022*1022*5, buf, GL_STATIC_DRAW_ARB);


As you can see both functions are pretty much same.

fprintf(fout, "%d %d %d %d %d\n", i, j, partIBSizes[j], partIB[j], partInd[0]);

prints same thing for both functions, however on first run of program, it generates world and saves it but crashes after draw method. However on second run it loads the world but does not crash. What might be the problem?

Also my render function. It creashes on first iteration of loop, after the glDrawElements call.


glBindBufferARB(GL_ARRAY_BUFFER_ARB, vb);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0));
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(12));
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), BUFFER_OFFSET(24));


for(int i=0; i<16; i++){
for(int j=0; j<16; j++){
//fprintf(fout, "%d %d %d %d\n", i, j, partIBSizes[j], partIB[j]);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, partIB[j]);
glDrawElements(GL_TRIANGLES, partIBSizes[j], GL_UNSIGNED_INT, BUFFER_OFFSET(0));

}
}

Share this post


Link to post
Share on other sites
Advertisement
wow, found the problem. I am allocating way too much memory and it somehow causes this problem.

I should be more careful while using something like 1024*1024*12 in malloc calls.

Share this post


Link to post
Share on other sites
On an unrelated note, I am having artifacts caused by z buffer. I am planning to use different depth test settings for farther part of the terrain. Do you thing this is viable


glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (45.0f, (GLfloat)(g_window->init.width)/(GLfloat)(g_window->init.height), 1000, 1500000.0f);
glMatrixMode (GL_MODELVIEW);

//render the low quality model of the terrain that is farther than the camera


glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (45.0f, (GLfloat)(g_window->init.width)/(GLfloat)(g_window->init.height), 0.1, 10000.0f);
glMatrixMode (GL_MODELVIEW);
glClear(GL_DEPTH_BUFFER_BIT);

//render the higher quality model around the camera

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!