Jump to content
  • Advertisement
Sign in to follow this  
Kenny77

SDL Window (Trying to use OOD)

This topic is 3975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to understand OOD while using SDL/C++, and while this program runs, it flashes and closes. When I try to find out what's going on (running it through the debugger) I get an access violation error. Main
#include <cstdlib>
#include <iostream>

#include "SDL/include/SDL/SDL.h"

#include "Graphics.h"


int main(int argc, char *argv[])
{   
    bool done = 0;
    
    Graphics GGraphics;
    
    while (done == 0)
    {
          SDL_Event event;
          
          while (SDL_PollEvent(&event))
          {
                if (event.type == SDL_QUIT)
                {
                   done = 1;
                }
          }
          
          GGraphics.EndScene();
    }
    
    SDL_Quit();
    
    return 0;
}


Graphics.cpp
#include "Graphics.h"

Graphics::Graphics()
{
     //Initialize SDL's video component                         
     SDL_Init(SDL_INIT_VIDEO);
       
     SDL_Surface *screen = NULL;
       
     screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);                                                        
}

void Graphics::EndScene()
{
     SDL_Flip(screen);     
}


Graphics.h
#include "SDL/include/SDL/SDL.h"

class Graphics
{
      public:
             SDL_Surface *screen;
             
             //Class constructor
             Graphics();
             
             //Our last call before the frame gets drawn
             void EndScene();                    
};


Share this post


Link to post
Share on other sites
Advertisement
I don't think that would help but 'done' is a boolean so you should
change the while to done==false and the assignment to done=true...
also try to remove the flip because when I compiled your code that was the
place the debugger was complaining about...

Share this post


Link to post
Share on other sites
The problem is, that you need to flip the same SDL_Surface that you used SDL_SetVideoMode on. You are defining a new one in the graphics constructor, then flipping with an uninitialised one that is defined in the class.

Just take out


SDL_Surface *screen = NULL;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!