Jump to content
  • Advertisement
Sign in to follow this  
s33d

Mipmapping Issues

This topic is 2211 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

glGenerateMipmap() doesn't play well with my application. When the call is present, it crashes before my window pops up. The function where I have it is never called (I did this for debugging), but it still causes a crash. I know it's to blame because when I comment it out, everything works fine.

I heard there were issues with this call and ATI cards, but that's not my issue--again, the function with the line in it is never called, so I don't know why it's acting up (also no idea how to debug it--any breakpoint set there is never reached). It compiles correctly, so I'm pretty sure I have my libraries set up properly. Edited by s33d

Share this post


Link to post
Share on other sites
Advertisement
Kinda goes against the logic and basic principals of programming, if the said line of code crashes your program even though it's not executed. blink.png Are you absolutely, positively sure it's not executed? At all? In any circumstances? Maybe you should post the related code, so we might have a better chance to get it solved. :) Edited by Manabreak

Share this post


Link to post
Share on other sites
Yeah, that's why I'm so stumped. It makes 0 sense.
This is my main function:

int main(int argc, char **argv) {
printf("Main entry.\n");
//initialize GLUT
glutInit(&argc, argv);
//display mode: color index/RGB, 1x/2x buffering
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
//window size (width, height)
glutInitWindowSize(300,400);
glutInitWindowPosition(0,0);
glutCreateWindow("Main Window");
//assign a clear color (R,G,B,alpha)
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//shading technique
glShadeModel(GL_SMOOTH);
//viewport
glViewport(0,0,300,400);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(300/400),1.0,1000.0);
glEnable(GL_DEPTH_TEST); // We enable the depth test (also called z buffer)
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled)
// //enable and load texture
// glEnable(GL_TEXTURE_2D);
// pyramid.texture_id = loadImg("C:\\00-raiser.bmp");
// if(pyramid.texture_id == -1){
// MessageBox(NULL,"Image not found.", "Error", MB_OK | MB_ICONERROR);
// exit (0);
// }
//required functions
glutDisplayFunc(sSimDisp);
glutReshapeFunc(sSimResh);
glutIdleFunc(sSimDisp);
glutKeyboardFunc(keyboard);
glutSpecialFunc(keyboard_s);
printf("main OK, now looping.\n");
//let GLUT do things
glutMainLoop();
// system("cls");
//loop forever
return 0;
}

As you can see, loadImg is called just once (a ctrl-f confirms this) and it's commented out here. the loadImg function itself:

int loadImg(char *filename){
//pointer to memory for image storage
unsigned char *texture;
int index = 0;
int index1 = 0;
//pointer to file opened with "fopen"
FILE* file_ptr;
//mem allocation info scooped off of bitmap file
BITMAPFILEHEADER fileheader;
//size info scooped from bitmap
BITMAPINFOHEADER infoheader;
RGBTRIPLE rgb;
//increment texture index for tracking
texture_index++;
//open file as binary, if non-existent return "-1"
if((file_ptr = fopen(filename, "rb")) == NULL){
return(-1);
}
//read the file header
fread(&fileheader, sizeof(infoheader), 1, file_ptr);
fseek(file_ptr, sizeof(fileheader), SEEK_SET);
//read the info header
fread(&infoheader, sizeof(infoheader), 1, file_ptr);
//allocate memory for image (width x height x color depth) and clean it out
texture = (byte*) malloc(infoheader.biWidth * infoheader.biHeight * 4);
memset(texture, 0, infoheader.biWidth * infoheader.biHeight * 4);
//parse through every pixel
for (index=0; index < infoheader.biWidth*infoheader.biHeight; index++){
//load a single pixel
fread(&rgb, sizeof(rgb), 1, file_ptr);
//store the rgb data (R, G, B, Alpha)
texture[index1 + 0] = rgb.rgbtRed;
texture[index1 + 1] = rgb.rgbtGreen;
texture[index1 + 2] = rgb.rgbtBlue;
texture[index1 + 3] = 255;
//next pixel
index1 += 4;
}
fclose(file_ptr);
//just in case
GLuint error = glGetError();
glGenTextures(1, &texture_index);
//give texture an id
glBindTexture(GL_TEXTURE_2D, texture_index);
//The next commands sets the texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // If the u,v coordinates overflow the range 0,1 the image is repeated
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // The magnification function ("linear" produces better results)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //The minifying function
error = glGetError();
//need this explained
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
error = glGetError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);
//need this explained
// glGenerateMipmap(GL_TEXTURE_2D);
error = glGetError();
//free up the texture loading memory
free(texture);
//return the texture id
return(texture_index);
}

I'm going to try reinstalling GLEW, maybe there's something wrong with the lib I have. Edited by s33d

Share this post


Link to post
Share on other sites
This actually sounds like a memory leak/overflow issue that may be completely unrelated to the code you're looking at. Unless you have a debugging framework in place, IMO your best bet is to start to systematically comment out UNRELATED chunks of code and see how they affect the behavior. Read this to acquaint yourself with memory leak debugging.

I'm willing to bet that the likelihood is >99.99% that GLEW isn't to blame here. The problem may be as simple as forgetting to write a NULL byte at the end of a string or overflowing an array by one element. In other words - basically anything that can in some form or fashion allow another part of your code to, for example, corrupt an address that you're calling.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!