Skip to content

Commit

Permalink
Merge pull request #206 from LVLVbNH/nosound_crashes_fix
Browse files Browse the repository at this point in the history
prevent CTD with -nosound (close #168)
  • Loading branch information
Xottab-DUTY authored May 25, 2018
2 parents d95f3fd + 0ec18b1 commit 04a3ca4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
9 changes: 5 additions & 4 deletions src/xrGame/script_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

CScriptSound::CScriptSound(LPCSTR caSoundName, ESoundTypes sound_type)
{
m_bIsNoSound = strstr(Core.Params, "-nosound");
m_caSoundToPlay = caSoundName;
string_path l_caFileName;
VERIFY(GEnv.Sound);
Expand All @@ -35,7 +36,7 @@ CScriptSound::~CScriptSound()

Fvector CScriptSound::GetPosition() const
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
const CSound_params* l_tpSoundParams = m_sound.get_params();
if (l_tpSoundParams)
return (l_tpSoundParams->position);
Expand All @@ -48,15 +49,15 @@ Fvector CScriptSound::GetPosition() const

void CScriptSound::Play(CScriptGameObject* object, float delay, int flags)
{
THROW3(m_sound._handle(), "There is no sound", *m_caSoundToPlay);
THROW3(m_sound._handle() || m_bIsNoSound, "There is no sound", *m_caSoundToPlay);
// Msg ("%6d : CScriptSound::Play (%s), delay %f, flags
//%d",Device.dwTimeGlobal,m_sound._handle()->file_name(),delay,flags);
m_sound.play((object) ? &object->object() : NULL, flags, delay);
}

void CScriptSound::PlayAtPos(CScriptGameObject* object, const Fvector& position, float delay, int flags)
{
THROW3(m_sound._handle(), "There is no sound", *m_caSoundToPlay);
THROW3(m_sound._handle() || m_bIsNoSound, "There is no sound", *m_caSoundToPlay);
// Msg ("%6d : CScriptSound::Play (%s), delay %f, flags
//%d",m_sound._handle()->file_name(),delay,flags);
m_sound.play_at_pos((object) ? &object->object() : NULL, position, flags, delay);
Expand All @@ -65,6 +66,6 @@ void CScriptSound::PlayAtPos(CScriptGameObject* object, const Fvector& position,
void CScriptSound::PlayNoFeedback(
CScriptGameObject* object, u32 flags /*!< Looping */, float delay /*!< Delay */, Fvector pos, float vol)
{
THROW3(m_sound._handle(), "There is no sound", *m_caSoundToPlay);
THROW3(m_sound._handle() || m_bIsNoSound, "There is no sound", *m_caSoundToPlay);
m_sound.play_no_feedback((object) ? &object->object() : NULL, flags, delay, &pos, &vol);
}
1 change: 1 addition & 0 deletions src/xrGame/script_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CScriptSound
{
mutable ref_sound m_sound;
shared_str m_caSoundToPlay;
bool m_bIsNoSound = false;

friend class CScriptSoundAction;

Expand Down
28 changes: 14 additions & 14 deletions src/xrGame/script_sound_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

IC u32 CScriptSound::Length()
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
return iFloor(m_sound.get_length_sec() * 1000.0f);
}

Expand All @@ -28,37 +28,37 @@ IC void CScriptSound::PlayAtPos(CScriptGameObject* object, const Fvector& positi

IC void CScriptSound::SetMinDistance(const float fMinDistance)
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
m_sound.set_range(fMinDistance, GetMaxDistance());
}

IC void CScriptSound::SetMaxDistance(const float fMaxDistance)
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
m_sound.set_range(GetMinDistance(), fMaxDistance);
}

IC const float CScriptSound::GetFrequency() const
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
return (m_sound.get_params()->freq);
}

IC const float CScriptSound::GetMinDistance() const
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
return (m_sound.get_params()->min_distance);
}

IC const float CScriptSound::GetMaxDistance() const
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
return (m_sound.get_params()->max_distance);
}

IC const float CScriptSound::GetVolume() const
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
return (m_sound.get_params()->volume);
}

Expand All @@ -72,42 +72,42 @@ IC bool CScriptSound::IsPlaying() const
IC void CScriptSound::AttachTail(LPCSTR caSoundName) { m_sound.attach_tail(caSoundName); }
IC void CScriptSound::Stop()
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
m_sound.stop();
}

IC void CScriptSound::StopDeferred()
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
m_sound.stop_deferred();
}

IC void CScriptSound::SetPosition(const Fvector& position)
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
m_sound.set_position(position);
}

IC void CScriptSound::SetFrequency(float frequency)
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
m_sound.set_frequency(frequency);
}

IC void CScriptSound::SetVolume(float volume)
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
m_sound.set_volume(volume);
}

IC const CSound_params* CScriptSound::GetParams()
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
return (m_sound.get_params());
}

IC void CScriptSound::SetParams(CSound_params* sound_params)
{
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || m_bIsNoSound);
m_sound.set_params(sound_params);
}
21 changes: 13 additions & 8 deletions src/xrGame/ui/UIComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,23 @@ void CUIComboBox::SetCurrentOptValue()
m_list_box.Clear();
const xr_token* tok = GetOptToken();

while (tok->name)
if (tok)
{
if (m_disabled.end() == std::find(m_disabled.begin(), m_disabled.end(), tok->id))
while (tok->name)
{
AddItem_(tok->name, tok->id);
if (m_disabled.end() == std::find(m_disabled.begin(), m_disabled.end(), tok->id))
{
AddItem_(tok->name, tok->id);
}
tok++;
}
tok++;
}

LPCSTR cur_val = *CStringTable().translate(GetOptTokenValue());
m_text.SetText(cur_val);
m_list_box.SetSelectedText(cur_val);
LPCSTR cur_val = *CStringTable().translate(GetOptTokenValue());
m_text.SetText(cur_val);
m_list_box.SetSelectedText(cur_val);
}
else
m_text.SetText("-");

CUIListBoxItem* itm = m_list_box.GetSelectedItem();
if (itm)
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ui/UIGameTutorialVideoItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void CUISequenceVideoItem::Load(CUIXml* xml, int idx)
if (snd_name && snd_name[0])
{
m_sound.create(snd_name, st_Effect, sg_Undefined);
VERIFY(m_sound._handle());
VERIFY(m_sound._handle() || strstr(Core.Params, "-nosound"));
}
xml->SetLocalRoot(_stored_root);
}
Expand Down

0 comments on commit 04a3ca4

Please sign in to comment.