Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -171,20 +171,10 @@ return -1; } #endif -#ifdef OF_NINTENDO_SWITCH -static bool initialized = false; - -OF_DESTRUCTOR() -{ - if (initialized) - romfsExit(); -} -#endif - @implementation OFFile + (void)initialize { if (self != [OFFile class]) return; @@ -205,11 +195,11 @@ if (R_SUCCEEDED(romfsInit())) /* * Errors are intentionally ignored, as it's possible we just * have no romfs. */ - initialized = true; + atexit((void (*)(void))romfsExit); #endif } + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode { Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -54,10 +54,16 @@ #ifdef OF_NINTENDO_3DS # include <3ds/types.h> # include <3ds/services/soc.h> #endif + +#ifdef OF_NINTENDO_SWITCH +# define id nx_id +# include +# undef id +#endif #if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) static OFMutex *mutex; static void @@ -128,20 +134,20 @@ if (socInit(ctx, 0x100000) != 0) return; atexit((void (*)(void))socExit); +# elif defined(OF_NINTENDO_SWITCH) + if (R_FAILED(socketInitializeDefault())) + return; + + atexit(socketExit); # endif # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) mutex = [[OFMutex alloc] init]; atexit(releaseMutex); - -# ifdef OF_WII - if (OFSpinlockNew(&spinlock) != 0) - return; -# endif # endif initSuccessful = true; }