Sign in to follow this  

SDL Window (Trying to use OOD)

This topic is 3664 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
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

This topic is 3664 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this