Use raw pointer for sound manager (#107)
Use raw pointer for sound manager to avoid a crash in destructor after exit(0)
This commit is contained in:
parent
3ecb0895aa
commit
8535658791
@ -80,7 +80,7 @@ ClientLauncher::~ClientLauncher()
|
|||||||
delete RenderingEngine::get_instance();
|
delete RenderingEngine::get_instance();
|
||||||
|
|
||||||
#if USE_SOUND
|
#if USE_SOUND
|
||||||
g_sound_manager_singleton.reset();
|
deleteSoundManagerSingleton(g_sound_manager_singleton);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +101,11 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
|
|||||||
return RenderingEngine::print_video_modes();
|
return RenderingEngine::print_video_modes();
|
||||||
|
|
||||||
#if USE_SOUND
|
#if USE_SOUND
|
||||||
if (g_settings->getBool("enable_sound"))
|
if (g_settings->getBool("enable_sound")) {
|
||||||
|
// Check if it's already created just in case
|
||||||
|
if (!g_sound_manager_singleton)
|
||||||
g_sound_manager_singleton = createSoundManagerSingleton();
|
g_sound_manager_singleton = createSoundManagerSingleton();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!init_engine()) {
|
if (!init_engine()) {
|
||||||
|
@ -1292,9 +1292,9 @@ bool Game::init(
|
|||||||
bool Game::initSound()
|
bool Game::initSound()
|
||||||
{
|
{
|
||||||
#if USE_SOUND
|
#if USE_SOUND
|
||||||
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) {
|
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton) {
|
||||||
infostream << "Attempting to use OpenAL audio" << std::endl;
|
infostream << "Attempting to use OpenAL audio" << std::endl;
|
||||||
sound = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher);
|
sound = createOpenALSoundManager(g_sound_manager_singleton, &soundfetcher);
|
||||||
if (!sound)
|
if (!sound)
|
||||||
infostream << "Failed to initialize OpenAL audio" << std::endl;
|
infostream << "Failed to initialize OpenAL audio" << std::endl;
|
||||||
} else
|
} else
|
||||||
|
@ -50,7 +50,7 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#define BUFFER_SIZE 30000
|
#define BUFFER_SIZE 30000
|
||||||
|
|
||||||
std::shared_ptr<SoundManagerSingleton> g_sound_manager_singleton;
|
SoundManagerSingleton* g_sound_manager_singleton = nullptr;
|
||||||
|
|
||||||
typedef std::unique_ptr<ALCdevice, void (*)(ALCdevice *p)> unique_ptr_alcdevice;
|
typedef std::unique_ptr<ALCdevice, void (*)(ALCdevice *p)> unique_ptr_alcdevice;
|
||||||
typedef std::unique_ptr<ALCcontext, void(*)(ALCcontext *p)> unique_ptr_alccontext;
|
typedef std::unique_ptr<ALCcontext, void(*)(ALCcontext *p)> unique_ptr_alccontext;
|
||||||
@ -707,15 +707,22 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton()
|
SoundManagerSingleton* createSoundManagerSingleton()
|
||||||
{
|
{
|
||||||
auto smg = std::make_shared<SoundManagerSingleton>();
|
auto smg = new SoundManagerSingleton();
|
||||||
if (!smg->init()) {
|
if (!smg->init()) {
|
||||||
smg.reset();
|
delete smg;
|
||||||
|
smg = nullptr;
|
||||||
}
|
}
|
||||||
return smg;
|
return smg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deleteSoundManagerSingleton(SoundManagerSingleton* smg)
|
||||||
|
{
|
||||||
|
delete smg;
|
||||||
|
smg = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
ISoundManager *createOpenALSoundManager(SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher)
|
ISoundManager *createOpenALSoundManager(SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher)
|
||||||
{
|
{
|
||||||
return new OpenALSoundManager(smg, fetcher);
|
return new OpenALSoundManager(smg, fetcher);
|
||||||
|
@ -24,8 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
class SoundManagerSingleton;
|
class SoundManagerSingleton;
|
||||||
extern std::shared_ptr<SoundManagerSingleton> g_sound_manager_singleton;
|
extern SoundManagerSingleton* g_sound_manager_singleton;
|
||||||
|
|
||||||
std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton();
|
SoundManagerSingleton* createSoundManagerSingleton();
|
||||||
|
void deleteSoundManagerSingleton(SoundManagerSingleton* smg);
|
||||||
ISoundManager *createOpenALSoundManager(
|
ISoundManager *createOpenALSoundManager(
|
||||||
SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher);
|
SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher);
|
||||||
|
@ -150,8 +150,8 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
|||||||
//create soundmanager
|
//create soundmanager
|
||||||
MenuMusicFetcher soundfetcher;
|
MenuMusicFetcher soundfetcher;
|
||||||
#if USE_SOUND
|
#if USE_SOUND
|
||||||
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get())
|
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton)
|
||||||
m_sound_manager = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher);
|
m_sound_manager = createOpenALSoundManager(g_sound_manager_singleton, &soundfetcher);
|
||||||
#endif
|
#endif
|
||||||
if (!m_sound_manager)
|
if (!m_sound_manager)
|
||||||
m_sound_manager = &dummySoundManager;
|
m_sound_manager = &dummySoundManager;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user