problem with SDL screen

The problem is that it says screen cannot be evaluated in this function
1
2
3
4
void Graphics::ClearScreen()
{
SDL_FillRect( GetScreen(), NULL, SDL_MapRGB( screen->format, 255, 255, 255 ) );
}


even though screen in defined in this function
1
2
3
4
5
Graphics::Graphics()
{
	SDL_Init(SDL_INIT_VIDEO);
	screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
}



Here is the error
1
2
3
4
Unhandled exeption at 0x68129d00 in MyGame.exe:0xC000000: Access
violation reading location 0x0000013c.

[Break][Continue]
You might have to lock the surface screen before you can modify it.
how do i lock it?
Google.
1
2
3
4
5
6
7
8
9
10
11
12
   if(SDL_MUSTLOCK(screen)) {
      if(SDL_LockSurface(screen) < 0) 
         return;
   }

   //Draw pixels to screen here

   if(SDL_MUSTLOCK(screen)) {
       SDL_UnlockSurface(screen);
   }
  
   SDL_Flip(screen); 
You shouldn't have to lock to do a FillRect. You typically only need to lock if you are doing pixel-level access.

I assume GetScreen returns screen?

Are you sure screen is non-null?
@Disch yup it is defined when a Graphics object is instantiated.
Right, but I don't see any if(screen) checks.

Have you confirmed that screen is non-null at the time ClearScreen is called?
EDIT: i forgot accidentally fucked something up before. Now when it gets to the bolded line it says the error below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
SDL_Surface* Graphics::LoadImage( std::string filename )
{
	//The image that's loaded
    SDL_Surface* loadedImage = NULL;

    //The optimized surface that will be used
    SDL_Surface* optimizedImage = NULL;

    //Load the image
    loadedImage = SDL_LoadBMP( filename.c_str() );

    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized surface
        optimizedImage = SDL_DisplayFormat( loadedImage );

        //Free the old surface
        SDL_FreeSurface( loadedImage );

        //If the surface was optimized
        if( optimizedImage != NULL )
        {
            //Color key surface
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 255, 0, 255 ) );
        }
    }

    //Return the optimized surface
    return optimizedImage;
}


1
2
First-chance exception at 0x68129d00 in MyGame.exe: 0xC0000005: Access violation reading location 0x0000013c.
Unhandled exception at 0x68129d00 in MyGame.exe: 0xC0000005: Access violation reading location 0x0000013c.


lol okay ill try that and edit this post with results
Last edited on
Topic archived. No new replies allowed.