I've been working on learning how to use SDL, by working through some of Marius' tutorials. However, in his third tutorial on using sprites, I'm having an issues. I've been pseudo-converting his code to valid C++ instead of C, and this loop is causing me a problem. It will run through 3 times, and then exit with a bus error. Does anyone have any idea why? If I don't comment out the else clause at the bottom, it will always exit with that error. Anyone have any ideas?
Thanks,
Spidy
char buffer[255]; char filename[255]; char name[255]; int pause = 0; int red = 0; int green = 0; int blue = 0; cout << "creating spriteBase..." << endl; FILE *fp; sprintf(filename, "%s/info", dir); if((fp = fopen(filename, "r")) == NULL) { cout << "Error opening file " << filename << endl; exit(1); } fgets(buffer, 255, fp); sscanf(buffer, "FILES: %d", &itsNumberOfFrames); itsAnimation = new spriteFrame[itsNumberOfFrames]; itsBuilt = 1; int count = 0; cout << "Looping through file for properties..." << endl; while(!feof(fp) && count < itsNumberOfFrames) { cout << "Gettting property " << count << " of " << dir << "/" << filename << endl; fgets(buffer, 255, fp); // if we aren't at the end of the file, and the line doesn't start with a comment... if(buffer[0] != '#' && buffer[0] != '\r' && buffer[0] != '\0' && buffer[0] != '\n' && strlen(buffer) != 0) { // extract name of that frame's image, pause in milliseconds, red green blue values sscanf(buffer, "%s %d %d %d %d", name, &pause, &red, &green, &blue); sprintf(filename, "%s/%s", dir, name); // create a temporary surface to use for loading the image SDL_Surface *temp; // load in the image, checking to see if it worked correctly. if((temp = SDL_LoadBMP(filename)) == NULL) { cout << "Error Loading file" << filename << ": " << SDL_GetError() << endl; exit(1); } // if red is greater than or equal to zero, make that transparent if(red >= 0) { SDL_SetColorKey(temp, SDL_SRCCOLORKEY, SDL_MapRGB(temp->format, red, green, blue)); } itsAnimation[count].image = SDL_DisplayFormat(temp); // free the surface, so it can be used in the next iteration SDL_FreeSurface(temp); // store the pause we got out of the file into the pause value for the frame itsAnimation[count].pause = pause; //also, set the height/width values if they haven't been already if(!itsWidth) { itsWidth = itsAnimation[count].image->w; } if(!itsHeight) { itsHeight = itsAnimation[count].image->w; } count++; cout << "Got property " << count << " of " << dir << endl; } else { // cout << "Error loading \"" << filename << "\": " << SDL_GetError() << endl; // exit(1); } } fclose(fp); cout << "spriteBase created." << endl;