I’m still a new developer, and was doing some things with SDL in C, but
decided that C++ had some advantages over C. So I’ve been trying to get
this little snippet of code to do something, and have run into a
problem.
TrueMobile is a class. I create an instance of it called background,
and an SDL_Surface * gets initialized when I do so. It’s dimensions are
640x480.
What I can’t understand is why background’s destructor is called as
soon as it’s initialized. It makes using the class…troublesome at
best. I suppose I could go ahead and write a function outside the
constructor that initializes the surface, but it seems that avoids the
purpose of using a constructor in the first place.
Any ideas?
Thanks,
Austin
SOURCE___________
#ifndef ODDSOFT_ORG_SDL
#define ODDSOFT_ORG_SDL
#include<SDL/SDL.h>
#endif
#ifndef ODDSOFT_ORG_ORIENTATION
#define ODDSOFT_ORG_ORIENTATION
#include"include/orientation.h"
#endif
#ifndef ODDSOFT_ORG_TRUE_IMOBILE
#define ODDSOFT_ORG_TRUE_IMOBILE
#include “include/TrueImobile.h”
#endif
#ifndef ODDSOFT_ORG_IOSTREAM
#define ODDSOFT_ORG_IOSTREAM
#include
#endif
using namespace toehead;
int main()
{
atexit(SDL_Quit);
static SDL_Surface *screen;
if(SDL_Init(SDL_INIT_VIDEO != 0))
{
std::cout << "Unable to init video: " << SDL_GetError() << "\n";
return 1;
}
screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF |
SDL_FULLSCREEN);
if(screen == NULL)
{
std::cout << "Unable to set video mode: " << SDL_GetError() << “\n”;
return 1;
}
TrueImobile background("bmp/BackGround.bmp");
std::cout << "Before background is used.\n";
background.drawSprite(screen);
std::cout << "After background is used.\n";
SDL_FreeSurface(screen);
return 0;
}
OUTPUT____________
frame->w = 640 frame->h = 480 // From Constructor
Destructor! // From Destructor
Before background is used. // From main
src.x = 0 src.y = 0 // From drawSprite
src.w = 59428 src.h = 0 // From drawSprite
dest.x = 0 dest.y = 0 // From drawSprite
dest.h = 480 dest.w = 640 // From drawSprite
Now frame->w = 4384804 // From drawSprite
Now frame->h = -1014956032 // From drawSprite
After background is used. // From main
Destructor! // Destructor