Original Post
Hello all. Thanks for reading this thread.I am literally hours above this little piece of code and I have no idea what the heck the problem is.Honestly I got past the searching patiently point and got a little bit pissed , so I am going to take a walk for a while. But before I do I would like to present it to you people here , since you might find the answer.I am making a 2D game using SDL.I am still setting the engine up ... but I am literally stuck at drawing a button in the menu.The rest of the program logic is bound to be ok , since it runs ok if I use my ScreenManager's class applySurface function to apply the button as a simple image.But when I use the draw function to draw it inside the menu I get a runtime error , just when the program starts.When I use the debugger it says : An access violation ( segmentation fault ) raised in your program Unfortunately I am not sure how to use the debugger ( DevC++) correctly so I can't find exactly where.From lots of trial and error I think it is somewhere in my menu class.It is still incomplete but I am going to paste it here and if you can see something I am missing please do say so.Thanks in advance : [Edited by - Fukushousha on January 31, 2007 4:47:37 PM]
#ifndef MENU_HPP
#define MENU_HPP
#include <vector>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "ScreenManager.hpp"
#include "Button.hpp"
class Menu
{
public:
//a ScreenManager Object
ScreenManager scManager;
//a pointer to a test button
Button* b;
/* default constructor */
Menu()
{
b = new Button(500 , 600 , 16 , 16 , scManager.loadImage("images/towerButton.png") );
} ;
/*draws the menu*/
void draw(SDL_Surface* screen) ;
/*cleans up the buttons vector of the menu*/
void cleanUp();
private:
};
#endif
#include "menu.hpp"
/*draws the menu*/
void Menu::draw(SDL_Surface* screen)
{
scManager.applySurface(0 , 568 , scManager.loadImage("images/menu.jpg") , screen);
b->draw(screen);
}
/*cleans up the buttons vector of the menu*/
void Menu::cleanUp()
{
delete b;
}