|
CreateThread() crashs my Wii November 23, 2008 04:32PM | Registered: 17 years ago Posts: 14 |
struct boot_struct
{
public:
boot_struct( void );
~boot_struct( void );
private:
static void *BootScreenThread( void *arg );
static GameWindow *gwd;
static bool booting;
static lwp_t *pBootScreenHandle;
static Image *pBootScreenImage;
static Sprite *pBootScreenSprite;
};
#include "boot.h"
GameWindow *boot_struct::gwd = NULL;
bool boot_struct::booting = false;
lwp_t *boot_struct::pBootScreenHandle = NULL;
Image *boot_struct::pBootScreenImage = NULL;
Sprite *boot_struct::pBootScreenSprite = NULL;
void* boot_struct::BootScreenThread( void *arg )
{
pBootScreenImage = new Image;
pBootScreenSprite = new Sprite;
pBootScreenImage->LoadImage( BootScreen );
pBootScreenSprite->SetImage( pBootScreenImage );
pBootScreenSprite->SetStretchWidth( 1.0f/640.0f*width );
pBootScreenSprite->SetStretchHeight( 1.0f/480.0f*height );
while( booting )
{
WPAD_ScanPads();
u32 pressed = WPAD_ButtonsDown(0);
pBootScreenSprite->Draw();
gwd->Flush();
if( pressed & WPAD_BUTTON_HOME ) exit(0);
VIDEO_WaitVSync();
}
delete pBootScreenImage;
pBootScreenImage = NULL;
delete pBootScreenSprite;
pBootScreenSprite = NULL;
return NULL;
}
int boot_struct::ShowBootScreen( void )
{
booting = true;
gwd->InitVideo();
gwd->SetBackground( (GXColor){100, 100, 255} );
if( LWP_CreateThread( pBootScreenHandle, BootScreenThread, NULL, NULL, 0, 80 ) < 0 ) return 0;
return 1;
}
int boot_struct::HideBootScreen( void )
{
booting = false;
LWP_SuspendThread( *pBootScreenHandle );
gwd->StopVideo();
return 1;
}|
Re: CreateThread() crashs my Wii November 23, 2008 04:58PM | Admin Registered: 17 years ago Posts: 5,132 |
Image *Image1 = new Image();//You were missing the ()
|
Re: CreateThread() crashs my Wii November 23, 2008 05:40PM | Registered: 17 years ago Posts: 265 |
|
Re: CreateThread() crashs my Wii November 23, 2008 07:39PM | Registered: 17 years ago Posts: 443 |
|
Re: CreateThread() crashs my Wii November 23, 2008 07:41PM | Registered: 17 years ago Posts: 3 |
Quote
Arikado
Simple Reason: Your using a struct instead of a class. I don't know very much about the differences between the two, but since you're working in C++ maybe that's the reason.
Quote
EDIT:Declare your pointers to NULL before you delete them.
Quote
When constructing a new image use the following syntax:Image *Image1 = new Image();//You were missing the ()
Quote
whodares
Classes are also allowed code, structures are mearly for representing data
|
Re: CreateThread() crashs my Wii November 24, 2008 01:31PM | Registered: 17 years ago Posts: 22 |
|
Re: CreateThread() crashs my Wii November 24, 2008 03:16PM | Registered: 17 years ago Posts: 443 |
Quote
JoeNotCharlesNot true at all.Quote
whodares
Classes are also allowed code, structures are mearly for representing data
|
Re: CreateThread() crashs my Wii November 26, 2008 03:16PM | Registered: 17 years ago Posts: 14 |
Quote
shagkur
Hi,
declare your pBootScreenHandle just as "static lwp_t pBootScreenHandle" and initialize it with LWP_THREAD_NULL.
And then call LWP_CreateThread(&pBootScreenHandle,........). This function expects a pointer to a lwp_t handle.
While you already declare it as a pointer, initialized to NULL, LWP_CreateThread will dereferrence this pointer and thus is accessing an invalid memory location. BUMM it's crashing. LWP_CreateThread doesn't malloc the handle for you.
The other option is to allocate the memory for this handle on your own in ShowBootScreen before the call to LWP_CreateThread. This way you can leave the rest of the code as it is.
regards
shagkur
struct boot_struct
{
public:
boot_struct( void );
~boot_struct( void );
private:
static void *BootScreenThread( void *arg );
static GameWindow *gwd;
static bool booting;
static lwp_t pBootScreenHandle;
static Image *pBootScreenImage;
static Sprite *pBootScreenSprite;
};
#include "boot.h"
GameWindow *boot_struct::gwd = NULL;
bool boot_struct::booting = false;
lwp_t boot_struct::pBootScreenHandle = LWP_THREAD_NULL;
Image *boot_struct::pBootScreenImage = NULL;
Sprite *boot_struct::pBootScreenSprite = NULL;
void* boot_struct::BootScreenThread( void *arg )
{
pBootScreenImage = new Image;
pBootScreenSprite = new Sprite;
pBootScreenImage->LoadImage( BootScreen );
pBootScreenSprite->SetImage( pBootScreenImage );
pBootScreenSprite->SetStretchWidth( 1.0f/640.0f*width );
pBootScreenSprite->SetStretchHeight( 1.0f/480.0f*height );
while( booting )
{
WPAD_ScanPads();
u32 pressed = WPAD_ButtonsDown(0);
pBootScreenSprite->Draw();
gwd->Flush();
if( pressed & WPAD_BUTTON_HOME ) exit(0);
VIDEO_WaitVSync();
}
delete pBootScreenImage;
pBootScreenImage = NULL;
delete pBootScreenSprite;
pBootScreenSprite = NULL;
return NULL;
}
int boot_struct::ShowBootScreen( void )
{
booting = true;
gwd->InitVideo();
gwd->SetBackground( (GXColor){100, 100, 255} );
if( LWP_CreateThread( &pBootScreenHandle, BootScreenThread, NULL, NULL, 0, 80 ) < 0 ) return 0;
return 1;
}
int boot_struct::HideBootScreen( void )
{
booting = false;
LWP_SuspendThread( pBootScreenHandle );
gwd->StopVideo();
return 1;
}
struct boot_struct
{
public:
boot_struct( void );
~boot_struct( void );
private:
static void *BootScreenThread( void *arg );
static GameWindow *gwd;
static bool booting;
static lwp_t *pBootScreenHandle;
static Image *pBootScreenImage;
static Sprite *pBootScreenSprite;
};
#include "boot.h"
GameWindow *boot_struct::gwd = NULL;
bool boot_struct::booting = false;
lwp_t *boot_struct::pBootScreenHandle = NULL;
Image *boot_struct::pBootScreenImage = NULL;
Sprite *boot_struct::pBootScreenSprite = NULL;
void* boot_struct::BootScreenThread( void *arg )
{
pBootScreenImage = new Image;
pBootScreenSprite = new Sprite;
pBootScreenImage->LoadImage( BootScreen );
pBootScreenSprite->SetImage( pBootScreenImage );
pBootScreenSprite->SetStretchWidth( 1.0f/640.0f*width );
pBootScreenSprite->SetStretchHeight( 1.0f/480.0f*height );
while( booting )
{
WPAD_ScanPads();
u32 pressed = WPAD_ButtonsDown(0);
pBootScreenSprite->Draw();
gwd->Flush();
if( pressed & WPAD_BUTTON_HOME ) exit(0);
VIDEO_WaitVSync();
}
delete pBootScreenImage;
pBootScreenImage = NULL;
delete pBootScreenSprite;
pBootScreenSprite = NULL;
return NULL;
}
int boot_struct::ShowBootScreen( void )
{
booting = true;
pBootScreenHandle = (lwp_t*)malloc( 1024 ) //sizeof() didn't work for BootScreenThread...
gwd->InitVideo();
gwd->SetBackground( (GXColor){100, 100, 255} );
if( LWP_CreateThread( pBootScreenHandle, BootScreenThread, NULL, NULL, 0, 80 ) < 0 ) return 0;
return 1;
}
int boot_struct::HideBootScreen( void )
{
booting = false;
LWP_SuspendThread( *pBootScreenHandle );
gwd->StopVideo();
delete pBootScreenHandle;
pBootScreenHandle = NULL;
return 1;
}|
Re: CreateThread() crashs my Wii December 02, 2008 01:08PM | Registered: 17 years ago Posts: 10 |