Reputation: 422
I'm writing a simple game. I'm stock by a bug that i can't figure out what are the causes. In the code i write this:
DxFrame[0] = ImageLoader("Rome/Ball_Dx/RomeDx1.png");
DxFrame[1] = ImageLoader("Rome/Ball_Dx/RomeDx2.png");
DxFrame[2] = ImageLoader("Rome/Ball_Dx/RomeDx3.png");
DxFrame[3] = ImageLoader("Rome/Ball_Dx/RomeDx4.png");
DxFrame[4] = ImageLoader("Rome/Ball_Dx/RomeDx5.png");
SxFrame[0] = ImageLoader("Rome/Ball_Sx/RomeSx1.png");
SxFrame[1] = ImageLoader("Rome/Ball_Sx/RomeSx2.png");
SxFrame[2] = ImageLoader("Rome/Ball_Sx/RomeSx3.png");
SxFrame[3] = ImageLoader("Rome/Ball_Sx/RomeSx4.png");
SxFrame[4] = ImageLoader("Rome/Ball_Sx/RomeSx5.png");
But when I compile in the monitor DxFrame[4] is not what is should be. In fact he became SxFrame[0]. I can't understand why this happen.
Edit This is the image loader:
SDL_Surface* ImageLoader(string Image) {
SDL_Surface* LoadedImage = NULL;
SDL_Surface* OptimizedImage = NULL;
LoadedImage = IMG_Load(Image.c_str());
OptimizedImage = SDL_DisplayFormat(LoadedImage);
SDL_FreeSurface(LoadedImage);
return OptimizedImage;
}
I don't think there is nomore relevant code.
Upvotes: 0
Views: 126
Reputation: 36
Your arrays can hold 4 images but you are writing 5 in to them which will overwrite whatever comes after it.
Upvotes: 1