From 5974d05380caef05edf9e15519e58211e4addab0 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Tue, 23 Dec 2014 20:32:16 +0100 Subject: [PATCH] Create OpenAL device in main() and store in RGSSThreadData --- src/eventthread.h | 4 ++++ src/main.cpp | 33 +++++++++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/eventthread.h b/src/eventthread.h index 9f7f508..1c8d35a 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -37,6 +37,7 @@ #include struct RGSSThreadData; +typedef struct ALCdevice_struct ALCdevice; struct SDL_Window; class EventThread @@ -225,6 +226,7 @@ struct RGSSThreadData const char *argv0; SDL_Window *window; + ALCdevice *alcDev; Vec2 sizeResoRatio; Vec2i screenOffset; @@ -236,10 +238,12 @@ struct RGSSThreadData RGSSThreadData(EventThread *ethread, const char *argv0, SDL_Window *window, + ALCdevice *alcDev, const Config& newconf) : ethread(ethread), argv0(argv0), window(window), + alcDev(alcDev), sizeResoRatio(1, 1), config(newconf) {} diff --git a/src/main.cpp b/src/main.cpp index 6ec3092..48b98a8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -108,22 +108,11 @@ int rgssThreadFun(void *userdata) GLDebugLogger dLogger; /* Setup AL context */ - ALCdevice *alcDev = alcOpenDevice(0); - - if (!alcDev) - { - rgssThreadError(threadData, "Error opening OpenAL device"); - SDL_GL_DeleteContext(glCtx); - - return 0; - } - - ALCcontext *alcCtx = alcCreateContext(alcDev, 0); + ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0); if (!alcCtx) { rgssThreadError(threadData, "Error creating OpenAL context"); - alcCloseDevice(alcDev); SDL_GL_DeleteContext(glCtx); return 0; @@ -139,7 +128,6 @@ int rgssThreadFun(void *userdata) { rgssThreadError(threadData, exc.msg); alcDestroyContext(alcCtx); - alcCloseDevice(alcDev); SDL_GL_DeleteContext(glCtx); return 0; @@ -154,8 +142,6 @@ int rgssThreadFun(void *userdata) SharedState::finiInstance(); alcDestroyContext(alcCtx); - alcCloseDevice(alcDev); - SDL_GL_DeleteContext(glCtx); return 0; @@ -284,8 +270,22 @@ int main(int argc, char *argv[]) SDL_FreeSurface(iconImg); } + ALCdevice *alcDev = alcOpenDevice(0); + + if (!alcDev) + { + showInitError("Error opening OpenAL device"); + SDL_DestroyWindow(win); + TTF_Quit(); + IMG_Quit(); + SDL_Quit(); + + return 0; + } + EventThread eventThread; - RGSSThreadData rtData(&eventThread, argv[0], win, conf); + RGSSThreadData rtData(&eventThread, argv[0], win, + alcDev, conf); int winW, winH; SDL_GetWindowSize(win, &winW, &winH); @@ -338,6 +338,7 @@ int main(int argc, char *argv[]) Debug() << "Shutting down."; + alcCloseDevice(alcDev); SDL_DestroyWindow(win); Sound_Quit();