fopen in a thread with no console = freeze October 24, 2009 05:05AM | Registered: 15 years ago Posts: 78 |
#includeDownload: fopen.tar.bz2#include #include #include #include #include #include #define FILE_NAME "sd:/testfile.txt" //////////////////////////////////////////////////////////////////////////////// // VIDEO INIT //////////////////////////////////////////////////////////////////////////////// static void *xfb = NULL; static GXRModeObj *rmode = NULL; static void init_video() { VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); } //////////////////////////////////////////////////////////////////////////////// // THREAD //////////////////////////////////////////////////////////////////////////////// #define THREAD_PRIO 90 #define THREAD_STACK_SIZE 1024*8 static lwp_t thread = LWP_THREAD_NULL; static u8 stack[ THREAD_STACK_SIZE ]; static void *thread_main( void *unused ) { _break(); FILE *handle = fopen( FILE_NAME, "rb" ); /* if init_video wasn't called in main(), the above call to fopen will * freeze the Wii and the follow breakpoint will never be reached */ _break(); if ( handle == NULL ) { return NULL; } fclose( handle ); return NULL; } //////////////////////////////////////////////////////////////////////////////// // MAIN //////////////////////////////////////////////////////////////////////////////// int main() { DEBUG_Init( GDBSTUB_DEVICE_USB, 1 ); _break(); /* If init_video() is not called, the Wii will freeze at the * fopen() call in thread_main() */ init_video(); fatInitDefault(); /* Create the thread that calls fopen */ if ( LWP_CreateThread( &thread, thread_main, NULL, stack, THREAD_STACK_SIZE, THREAD_PRIO ) != 0 ) { exit( EXIT_FAILURE ); } WPAD_Init(); while(1) { WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); if ( pressed & WPAD_BUTTON_HOME ) exit(0); VIDEO_WaitVSync(); } return 0; }
Re: fopen in a thread with no console = freeze October 24, 2009 07:57AM | Registered: 15 years ago Posts: 703 |
Re: fopen in a thread with no console = freeze October 24, 2009 03:54PM | Registered: 15 years ago Posts: 73 |
Re: fopen in a thread with no console = freeze October 30, 2009 10:42PM | Registered: 15 years ago Posts: 78 |