Jump to content


Introduction to C++ with Game Development


7 replies to this topic

#1 ShellShock

    New Member

  • Members
  • Pip
  • 3 posts

Posted 07 December 2011 - 02:31 PM

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,

#2 PnP Bios

    Member

  • Members
  • PipPip
  • 47 posts

Posted 07 December 2011 - 05:23 PM

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

http://sdl.beuc.net/...DL_SetVideoMode

#3 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 07 December 2011 - 06:07 PM

Double-check that your graphics drivers are up-to-date.
reedbeta.com - developer blog, OpenGL demos, and other projects

#4 ShellShock

    New Member

  • Members
  • Pip
  • 3 posts

Posted 08 December 2011 - 09:02 AM

View PostPnP Bios, on 07 December 2011 - 05:23 PM, said:

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;
}


View PostReedbeta, on 07 December 2011 - 06:07 PM, said:

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.goog...l&ct=clnk&gl=nl
but the answers in this topic are not really clearly.

#5 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 08 December 2011 - 10:02 AM

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;
}

"Stupid bug! You go squish now!!" - Homer Simpson

#6 ShellShock

    New Member

  • Members
  • Pip
  • 3 posts

Posted 08 December 2011 - 11:16 AM

View PostKenneth Gorking, on 08 December 2011 - 10:02 AM, said:

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

#7 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 08 December 2011 - 08:22 PM

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

http://forums.libsdl...opic.php?t=5730
"Stupid bug! You go squish now!!" - Homer Simpson

#8 TTTNL

    Member

  • Members
  • PipPip
  • 48 posts

Posted 27 December 2012 - 04:07 PM

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

View PostTTTNL, on 27 December 2012 - 01:29 AM, said:

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.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users