Ive created a SdlWrapper for myself to use. From times to times it works but sometimes I just gets access violation when I blit from a surface to the screen. But it have always solved itself somehow. :S But this time I want to find out whats wrong and fix it once and for all.
This how my draw image function looks like:
void SdlWrapper::DrawImg(SDL_Surface* img, int x, int y) { // draws the image at those coordinates on the screen
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);
}
Debugger says that img is defined 0x00397a58, so there should be some image there. X and y are both 0.
Now I tested something, and I found out that the exact same code works in main but not in a class's member function.
I ran:
SDL_Surface* temp;
temp = Sdl->LoadBmp("0");
Sdl->DrawImg(temp, 50, 50);
In main, everything was fine. But if I ran it in the gameclass render world function, it got a access violation.
The function where I get the access violation now looks likes this:
void Soduko::Game() {
SDL_Surface* temp;
temp = Sdl->LoadBmp("0");
Sdl->DrawImg(temp, 50, 50);
return;
for(int y = 0; y <= 9; y++) {
for(int x = 0; x <= 9; y++) {
cout << slot[(y*9)+x] << endl << numberBmp[ slot[(y*9)+x] ] << endl;
Sdl->DrawImg(numberBmp[ slot[(y*9)+x] ], x*32, y*32);
}
}
}
Im trying to make a Soduko game btw. :) But there you see I try to do the exact same thing as in main. One succeds one fails. Although the access violation comes at the blitsurface line in the sdlwrapper member class. Whats causing all this?
If you want to see more code, tell me and I post the entire classes.
Thanks in advance.