Welcome! Log In Create A New Profile

Advanced

SDL Thread Error ?

Posted by scanff 
SDL Thread Error ?
December 16, 2008 05:52AM
Hello,

I'm trying to port a game I made to the Wii. I'm using the SDL libs. I've compiled and built everything via devkit and put the game on the SD card. When I run it via the HBC I get the following error - "sdl not configured with thread support". I've identified the SDL_INIT_TIMER and SDL_GetTicks() as the culprits.

Does anyone know why I'm getting this issue? Or if it can't be solved point me to a tickcount/timer function for the Wii.

I'm building on WinXP using the latest devkit release, I believe it was updated today.

Thanks :)
Re: SDL Thread Error ?
December 16, 2008 08:50AM
After browsing around here I'm not so sure the SDL port is even worth it. I wanted to port my windows game to SDL for the Wii and Linux but I'm not so sure about using the SDL port after reading all the issues with it.

I also commented out the tickcount and let the code run way too fast but SDL still would not load the BMP files .... Just a simple thing like:

bool CFonts::LoadFontSet()
{
fontset = SDL_LoadBMP("images/fonts.bmp");
SDL_SetColorKey(fontset,SDL_SRCCOLORKEY, SDL_MapRGB(fontset->format, 0,0,0));

return true;
}

Maybe there is something I'm not doing correctly, as I said I'm new to this tool chain but the port to SDL runs fine under windows.

This is my first project for the Wii and I guess would like some advice as what are the better libraries to use. Here's what I need :)

I load my graphics as BMP's and need a way to mask them or set an alpha color. The music, sounds are currently ogg's so a sound lib that supports this would be useful.

I guess what I'm asking for is what the current developers think the best libraries are to use.
Re: SDL Thread Error ?
December 16, 2008 03:48PM
Quote

When I run it via the HBC I get the following error - "sdl not configured with thread support". I've identified the SDL_INIT_TIMER and SDL_GetTicks() as the culprits.

Have you tried not initializing the timer subsystem (e.g. do not pass SDL_INIT_TIMER)? This worked for the handful of SDL ports I've tried. I didn't see any timing issues when I did this.
Re: SDL Thread Error ?
December 16, 2008 07:13PM
Yes I tried that but SDL_GetTicks() is not valid or does not work if SDL_INIT_TIMER is not passed into the init function.
Re: SDL Thread Error ?
December 16, 2008 07:32PM
probably easiest way to fix it is to just rewrite the SDL_SYS_TimerInit(void) function in SDL-PORT/src/timer/gamecube/SDL_systimer.c

int SDL_SYS_TimerInit(void)
{
return(SDL_SetTimerThreaded(0));
}

or someone needs to rewrite SDL-PORT to use LWP threads

the current SDL_GetTicks() , maybe isn't the best way to handle ticks on Wii?

Uint32 SDL_GetTicks (void)
{
const Uint64 ticks = gettime();
const Uint64 ms = ticks / TB_TIMER_CLOCK;
return ms;
}

Troy



Edited 1 time(s). Last edit at 12/16/2008 07:33PM by GPF.
Re: SDL Thread Error ?
December 16, 2008 09:08PM
Thanks Troy,

I'll give that a go. I have an animation class that depends on a number of ms to pass before going to the next animation frame.
Re: SDL Thread Error ?
December 16, 2008 10:10PM
One more question (I did not want to spam with another thread).

When I set up my images I use:

fontset = SDL_LoadBMP("images/fonts.bmp"); (where the images are in a directory "images" in the dol file directory. SDL gives me an error (11.16 14:0:8: Couldn't open). Any advice ? Do the images need to be some where else.

The full patch for the dol is apps/wotef and apps/wotef/images

Thanks again
Re: SDL Thread Error ?
December 16, 2008 10:18PM
i believe you have to use

fontset = SDL_LoadBMP("/apps/wotef/images/fonts.bmp");

Troy



Edited 1 time(s). Last edit at 12/16/2008 10:19PM by GPF.
Re: SDL Thread Error ?
December 16, 2008 10:48PM
Makes sense but I'm still getting the SDL error :(
Re: SDL Thread Error ?
December 16, 2008 10:59PM
have you initialized libfat ?

fatInitDefault();

Troy
Re: SDL Thread Error ?
December 16, 2008 11:16PM
No but I just tried it with no luck. I would think that the SDL file routines would do that for you. Here's the start up code.

if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 ) {
exit(1);
}

if ( SDL_SetVideoMode( 640, 480, BITDEPTH,
(fullscreen ? SDL_FULLSCREEN : 0) | SDL_HWSURFACE | SDL_DOUBLEBUF ) < 0 ) {
exit(1);
}
screen = NULL;
screen = SDL_GetVideoSurface();
if (!screen) {
exit(1);
}

fatInitDefault();

ptheGame = new CGame;
if (!ptheGame->Init()) // fails here when trying to load a BMP
{
delete ptheGame; ptheGame = NULL;
exit(0);
}
Re: SDL Thread Error ?
December 16, 2008 11:34PM
might try calling fatInitDefault(); first before initializing SDL , or might try some other wii SDL app that has been released on the wiibrew application list and try compiling it to make sure your environment is function correctly.

Troy
Re: SDL Thread Error ?
December 16, 2008 11:58PM
Would you mind telling us how you resolved the original problem?
Re: SDL Thread Error ?
December 17, 2008 12:40AM
I created my own function as Troy said (not sure if it works as I can't get past the bitmap loading). But it builds.

// in header
#include "ogc/lwp_watchdog.h"
#define _WII_


// function
Uint64 GetTickCount()
{
#ifdef _WII_
const Uint64 ticks = gettime();
const Uint64 ms = ticks / TB_TIMER_CLOCK;
return ms;
#else
return SDL_GetTicks();
#endif

}



Edited 1 time(s). Last edit at 12/17/2008 12:41AM by scanff.
Re: SDL Thread Error ?
December 17, 2008 01:07AM
I took a quick look at the SDL file code and only thing I can guess is that to use the new libfat with SDL, will require the file code to be updated, probably just replace the current SDL-PORT/src/file/SDL_rwops.c from the sdl.org source release, or just comment out lines
423 #ifndef __GAMECUBE__

472 #endif

and update the Makefile.gamecube to not use its own old filecode, ie remove the following line
$(wildcard $(SDL_SRC_DIR)/file/gamecube/*.c) \

so that SDL will just use stdio api, instead of whatever method it used before.

Could also be possible to add a call to fatInitDefault(); similiar to how

SDL-PORT/src/file/SDL_gamecuberwops.c does it in the SDL_RWFromFile function as well.

Troy
Re: SDL Thread Error ?
December 17, 2008 08:18AM
Thanks Troy.

I've actually created my own solution that I'll post here. It's not very pretty but if you're looking to load a 24bit BMP then it works. :) Oh and my BMP's were created on Windows so I had to deal with endianness. If anyone uses this code please remember that the BYTE* for the pixel buffer needs to be deleted by you.

Here's the code.

typedef unsigned long       DWORD;
typedef unsigned char       BYTE;
typedef unsigned short      WORD;
typedef long LONG;

typedef struct {
        DWORD      biSize;
        LONG       biWidth;
        LONG       biHeight;
        WORD       biPlanes;
        WORD       biBitCount;
        DWORD      biCompression;
        DWORD      biSizeImage;
        LONG       biXPelsPerMeter;
        LONG       biYPelsPerMeter;
        DWORD      biClrUsed;
        DWORD      biClrImportant;
} BITMAPINFOHEADER;

typedef struct {
    char   magic[2];
	Uint32 bfSize;
	Uint16 bfReserved1;
	Uint16 bfReserved2;
	Uint32 bfOffBits;
} BITMAPFILEHEADER;

unsigned long ByteSwap2 (unsigned long nLongNumber)
{
   return (((nLongNumber&0x000000FF)<<24)+((nLongNumber&0x0000FF00)<<8)+
   ((nLongNumber&0x00FF0000)>>8)+((nLongNumber&0xFF000000)>>24));
}

SDL_Surface* bitmap_SDL(const char* path,BYTE* pixel_buffer)
{

	FILE* pFile = NULL;
	pFile = fopen(path,"rb");

	if (!pFile) return 0;

       SDL_Surface* s = NULL;

	BITMAPINFOHEADER bih;
	BITMAPFILEHEADER bfh;

	fread(&bfh,14,1,pFile);
	fread(&bih,40,1,pFile);

#ifdef _WII_
	// my bmps were created on Windows ... have to deal with Endianness
	bih.biWidth = ByteSwap2(bih.biWidth);
	bih.biHeight = ByteSwap2(bih.biHeight);
	bih.biSizeImage = ByteSwap2(bih.biSizeImage);
#endif
	
	if (bih.biSizeImage <= 0) return 0;


	pixel_buffer = new BYTE[bih.biSizeImage];
    BYTE* pitch = new BYTE[(bih.biWidth * 3)];

	if (!pixel_buffer || !pitch)
	{
		fclose(pFile);
		return 0;
	}

    // BMP's are stored upsidedown so flip it
    for( int i=0 ; i < bih.biHeight ; i++){
        fread(pitch,bih.biWidth * 3,1,pFile); // copy to buffer
        memcpy((BYTE*) pixel_buffer +( bih.biHeight - i - 1) * (bih.biWidth * 3) , (BYTE*)pitch, bih.biWidth * 3);

    }

    delete [] pitch;
    pitch = NULL;

#ifdef _WII_
	s = SDL_CreateRGBSurfaceFrom(pixel_buffer,bih.biWidth,bih.biHeight,24,bih.biWidth*3,0x000000FF, 0x0000FF00,0x00FF0000, 0);
#else
	s = SDL_CreateRGBSurfaceFrom(pixel_buffer,bih.biWidth,bih.biHeight,24,bih.biWidth*3,0x00FF0000, 0x0000FF00,0x000000FF, 0);
#endif

	fclose(pFile);

	if (!s) return 0;

	return s;
}
Re: SDL Thread Error ?
December 17, 2008 08:41AM
cool,

Another option might be to use SDL_LoadBMP_RW , and just read the file into a buffer and use the SDL_RWFromMem to load the BMP

Troy
Sorry, only registered users may post in this forum.

Click here to login