Okay gang,
Here’s my issue. The following code segfaults on execution of the
CApplication::Run() function. I have three files, Application.h,
Application.c and main.cc. The segfault occurs after exiting the
CApplication::Init() function. Any suggestions? When the code from the
CApplication::Init() function is moved to the main program body, it works
just fine.
Thanks,
David Wood
main.cc-----------------------
#include <stdio.h>
#include <Application.h>
void main() {
CApplication *App;
int retval;
if (App->Init() < 0) {
printf("Failed to Initialize Application:");
}
App->Run();
App->DeInit();
}
Application.h
/* Application.h – Application Class Header File */
#INCLUDE <stdio.h>
#INCLUDE <SDL/SDL.h>
#DEFINE SC_STARTED 0
#DEFINE SC_RUNNING 1
#DEFINE SC_STOPPED 2
class CApplication {
protected:
int AppState;
public:
int Init();
int Run();
int DeInit();
CApplication();
virtual ~CApplication();
};
Application.c
#INCLUDE “Application.h”
void CApplication::CApplication {
}
void CApplication::~CApplication {
}
int CApplication::Init() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Failed to Initialize Video:%s\n", SDL_GetError());
exit(-1);
}
screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
if (screen == NULL) {
printf("Could Not set video mode");
exit(-1);
}
return 0;
}
int CApplication::Run() {
}
int CApplication::DeInit() {
}
I screwed up this code listing, had to retype by hand and totally blew it.
Disregard this stupidity.> ----- Original Message -----
From: Wood, David [mailto:DWood@daedalcorp.com]
Sent: Wednesday, December 26, 2001 9:51 AM
To: 'sdl at libsdl.org’
Subject: [SDL] SegFault
Okay gang,
Here’s my issue. The following code segfaults on execution of the
CApplication::Run() function. I have three files, Application.h,
Application.c and main.cc. The segfault occurs after exiting the
CApplication::Init() function. Any suggestions? When the code from the
CApplication::Init() function is moved to the main program body, it works
just fine.
Thanks,
David Wood
#include <stdio.h>
#include <Application.h>
void main() {
CApplication *App;
int retval;
if (App->Init() < 0) {
printf(“Failed to Initialize Application:”);
}
App->Run();
App->DeInit();
}
Application.h
/* Application.h – Application Class Header File */
#INCLUDE <stdio.h>
#INCLUDE <SDL/SDL.h>
#DEFINE SC_STARTED 0
#DEFINE SC_RUNNING 1
#DEFINE SC_STOPPED 2
class CApplication {
protected:
int AppState;
public:
int Init();
int Run();
int DeInit();
CApplication();
virtual ~CApplication();
};
Application.c
#INCLUDE “Application.h”
void CApplication::CApplication {
}
void CApplication::~CApplication {
}
int CApplication::Init() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf(“Failed to Initialize Video:%s\n”, SDL_GetError());
exit(-1);
}
screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
if (screen == NULL) {
printf(“Could Not set video mode”);
exit(-1);
}
return 0;
}
int CApplication::Run() {
}
int CApplication::DeInit() {
}
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
— “Wood, David” skrev: >
Okay gang,
Here’s my issue. The following code segfaults on
execution of the
CApplication::Run() function. I have three files,
Application.h,
Application.c and main.cc. The segfault occurs
after exiting the
CApplication::Init() function. Any suggestions?
When the code from the
CApplication::Init() function is moved to the main
program body, it works
just fine.
Thanks,
David Wood
#include <stdio.h>
#include <Application.h>
void main() {
CApplication *App;
int retval;
if (App->Init() < 0) {
printf(“Failed to Initialize Application:”);
}
App->Run();
App->DeInit();
}
You need to allocate memory for the CApplication
pointer like so:
CApplication* App = new CApplication;
And when you are done, deallocate:
delete App;
/Anders_____________________________________________________
Do You Yahoo!?
se.yahoo.com
Thanks a bunch. I figured it was something like that.
David Wood> ----- Original Message -----
From: Anders Lowgren [mailto:andersdarliah@yahoo.com]
Sent: Wednesday, December 26, 2001 10:32 AM
To: sdl at libsdl.org
Subject: Re: [SDL] SegFault
— “Wood, David” skrev: >
Okay gang,
Here’s my issue. The following code segfaults on
execution of the
CApplication::Run() function. I have three files,
Application.h,
Application.c and main.cc. The segfault occurs
after exiting the
CApplication::Init() function. Any suggestions?
When the code from the
CApplication::Init() function is moved to the main
program body, it works
just fine.
Thanks,
David Wood
#include <stdio.h>
#include <Application.h>
void main() {
CApplication *App;
int retval;
if (App->Init() < 0) {
printf("Failed to Initialize Application:");
}
App->Run();
App->DeInit();
}
You need to allocate memory for the CApplication
pointer like so:
CApplication* App = new CApplication;
And when you are done, deallocate:
delete App;
/Anders
Do You Yahoo!?
se.yahoo.com
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl