Fix missing engine sound after changeKart

This commit is contained in:
Benau 2021-03-09 15:05:11 +08:00
parent 48b73520f0
commit 61d7aec726

View File

@ -175,8 +175,7 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
m_goo_sound = SFXManager::get()->getBuffer("goo"); m_goo_sound = SFXManager::get()->getBuffer("goo");
m_boing_sound = SFXManager::get()->getBuffer("boing"); m_boing_sound = SFXManager::get()->getBuffer("boing");
m_engine_sound = SFXManager::get()->createSoundSource(m_kart_properties->getEngineSfxType()); m_engine_sound = NULL;
for (int i = 0; i < EMITTER_COUNT; i++) for (int i = 0; i < EMITTER_COUNT; i++)
m_emitters[i] = SFXManager::get()->createSoundSource("crash"); m_emitters[i] = SFXManager::get()->createSoundSource("crash");
@ -196,9 +195,6 @@ void Kart::init(RaceManager::KartType type)
{ {
m_type = type; m_type = type;
if (!m_engine_sound)
Log::error("Kart","Could not allocate a sfx object for the kart. Further errors may ensue!");
loadData(type, UserConfigParams::m_animated_characters); loadData(type, UserConfigParams::m_animated_characters);
// m_skid_sound is loaded in loadData // m_skid_sound is loaded in loadData
initSound(); initSound();
@ -274,7 +270,8 @@ Kart::~Kart()
SFXManager::get()->deleteSFX(m_custom_sounds[n]); SFXManager::get()->deleteSFX(m_custom_sounds[n]);
}*/ }*/
m_engine_sound->deleteSFX(); if (m_engine_sound)
m_engine_sound->deleteSFX();
if (m_skid_sound) if (m_skid_sound)
m_skid_sound->deleteSFX(); m_skid_sound->deleteSFX();
@ -3016,7 +3013,13 @@ void Kart::loadData(RaceManager::KartType type, bool is_animated_model)
if (!GUIEngine::isNoGraphics()) if (!GUIEngine::isNoGraphics())
m_stars_effect.reset(new Stars(this)); m_stars_effect.reset(new Stars(this));
// Clear previous skid sound if exists // Clear previous sound if exists when changeKart
if (m_engine_sound)
m_engine_sound->deleteSFX();
m_engine_sound = SFXManager::get()->createSoundSource(m_kart_properties->getEngineSfxType());
if (!m_engine_sound)
Log::error("Kart","Could not allocate a sfx object for the kart. Further errors may ensue!");
if (m_skid_sound) if (m_skid_sound)
{ {
m_skid_sound->deleteSFX(); m_skid_sound->deleteSFX();