Introduction to C++ with Game Development

848f08f2a32e0452734522525b30882c
0
ShellShock 101 Dec 07, 2011 at 14:31

Hi,

You have probably many topics about this problem, but because the new site all google results redirecting me to the main forum page and makes it harder to find a solution. :(
But im following the tutorials of Introduction to C++ with Game Development.

But, i have an Unhandled exception problem at part 2. I know it means that i try to access a value that is NULL but i’m not sure how to solve this.
Here it crashed, i think SDL_GetVideoSurface(); is not returning any value.
template.cpp

SDL_Surface* s = SDL_GetVideoSurface();
surface = new Surface( SCRWIDTH, SCRHEIGHT, (Pixel*)s->pixels, s->pitch );

Im using latest Visual studio 2008 Express version.

Hope this is enough info to help ;)
Thanks,

7 Replies

Please log in or register to post a reply.

B3ed6ad08336f0458484147516e4fdaa
0
PnP_Bios 101 Dec 07, 2011 at 17:23

are you calling sdl set video mode before sdl get video surface?

http://sdl.beuc.net/sdl.wiki/SDL_SetVideoMode

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 07, 2011 at 18:07

Double-check that your graphics drivers are up-to-date.

848f08f2a32e0452734522525b30882c
0
ShellShock 101 Dec 08, 2011 at 09:02

@PnP Bios

are you calling sdl set video mode before sdl get video surface? http://sdl.beuc.net/…DL_SetVideoMode

Yes, the code is exactly the same as the tutorial. I downloaded the template package.

int main( int argc, char **argv )
{
redirectIO();
printf( "application started.\n" );
SDL_Init( SDL_INIT_VIDEO );
SDL_SetVideoMode( SCRWIDTH, SCRHEIGHT, 32, SDL_OPENGL );
SDL_EnableKeyRepeat( 0, 0 );
bool vbo = true;
if (!init())
{
  SDL_SetVideoMode( SCRWIDTH, SCRHEIGHT, 32, SDL_HWSURFACE|SDL_DOUBLEBUF );
  SDL_Surface* s = SDL_GetVideoSurface(); //
  surface = new Surface( SCRWIDTH, SCRHEIGHT, (Pixel*)s->pixels, s->pitch ); // Error
  surface->InitCharset();
  vbo = false;
  SDL_WM_SetCaption( "Template - FALLBACK", NULL );
}
else SDL_WM_SetCaption( "Template", NULL );
int exitapp = 0;
game = new Game();
game->SetTarget( surface );
while (!exitapp)
{
  if (vbo) // frame buffer swapping for VBO mode
  {
   swap();
   surface->SetBuffer( (Pixel*)framedata );
  }
  else  // frame buffer swapping for fall-back path
  {
   SDL_Surface* s = SDL_GetVideoSurface();
   SDL_UpdateRect( s, 0, 0, 0, 0 );
   framedata = (unsigned char*)s->pixels;
   surface->SetPitch( s->pitch / 4 );
   surface->SetBuffer( (Pixel*)framedata );
  }
  if (firstframe)
  {
   game->Init();
   firstframe = false;
  }
  // calculate frame time and pass it to game->Tick
  LARGE_INTEGER start, end;
  QueryPerformanceCounter( &start );
  game->Tick( (float)lastftime );
  QueryPerformanceCounter( &end );
  lastftime = float( end.QuadPart - start.QuadPart ) / float( ticksPS.QuadPart / 1000 );
  // event loop
//...event stuff
SDL_Quit();
return 1;
}

@Reedbeta

Double-check that your graphics drivers are up-to-date.

They are up-to-date.
I just don’t get it..

Looks like more people have the same problem: http://webcache.googleusercontent.com/search?q=cache:VepnAgb4vYUJ:www.devmaster.net/forums/showthread.php%3Fp%3D85649+devmaster+Introduction+to+C%2B%2B+unhandled+exception&cd=1&hl=nl&ct=clnk&gl=nl
but the answers in this topic are not really clearly.

46407cc1bdfbd2db4f6e8876d74f990a
0
Kenneth_Gorking 101 Dec 08, 2011 at 10:02

Try adding this code after the call to SDL_GetVideoSurface. It might give a useable error message.

if(s == 0)
{
  printf("SDL error: %s\n", SDL_GetError());
  return 1;
}
848f08f2a32e0452734522525b30882c
0
ShellShock 101 Dec 08, 2011 at 11:16

@Kenneth Gorking

Try adding this code after the call to SDL_GetVideoSurface. It might give a useable error message.

if(s == 0)
{
  printf("SDL error: %s\n", SDL_GetError());
  return 1;
}

Hm,
Im getting:
SDL error: SetProp() failed:invalid window handle

46407cc1bdfbd2db4f6e8876d74f990a
0
Kenneth_Gorking 101 Dec 08, 2011 at 20:22

There is a topic about it on SDLs forums, and it sounds like it’s a bug in SDL.

http://forums.libsdl.org/viewtopic.php?t=5730

991c178cbb1237d5e8e147aae5782cb9
0
TTTNL 101 Dec 27, 2012 at 16:07

maybe a bit late but i had the same problem, this solved it for me:
@TTTNL

I got it to work, the problem was my GPU driver, i have a ATI HD4890 and the 4000 series is only supported up to version 12.6 of Catalyst control center and i had 12.10 running, so i installed an the older version (12.6) which is compatible with my card and it ran just fine.