Skip to content

Commit 0ec18b1

Browse files
committed
prevent CTD with -nosound (close #168)
1 parent 5732c80 commit 0ec18b1

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

src/xrGame/script_sound.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
CScriptSound::CScriptSound(LPCSTR caSoundName, ESoundTypes sound_type)
1818
{
19+
m_bIsNoSound = strstr(Core.Params, "-nosound");
1920
m_caSoundToPlay = caSoundName;
2021
string_path l_caFileName;
2122
VERIFY(GEnv.Sound);
@@ -35,7 +36,7 @@ CScriptSound::~CScriptSound()
3536

3637
Fvector CScriptSound::GetPosition() const
3738
{
38-
VERIFY(m_sound._handle());
39+
VERIFY(m_sound._handle() || m_bIsNoSound);
3940
const CSound_params* l_tpSoundParams = m_sound.get_params();
4041
if (l_tpSoundParams)
4142
return (l_tpSoundParams->position);
@@ -48,15 +49,15 @@ Fvector CScriptSound::GetPosition() const
4849

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

5758
void CScriptSound::PlayAtPos(CScriptGameObject* object, const Fvector& position, float delay, int flags)
5859
{
59-
THROW3(m_sound._handle(), "There is no sound", *m_caSoundToPlay);
60+
THROW3(m_sound._handle() || m_bIsNoSound, "There is no sound", *m_caSoundToPlay);
6061
// Msg ("%6d : CScriptSound::Play (%s), delay %f, flags
6162
//%d",m_sound._handle()->file_name(),delay,flags);
6263
m_sound.play_at_pos((object) ? &object->object() : NULL, position, flags, delay);
@@ -65,6 +66,6 @@ void CScriptSound::PlayAtPos(CScriptGameObject* object, const Fvector& position,
6566
void CScriptSound::PlayNoFeedback(
6667
CScriptGameObject* object, u32 flags /*!< Looping */, float delay /*!< Delay */, Fvector pos, float vol)
6768
{
68-
THROW3(m_sound._handle(), "There is no sound", *m_caSoundToPlay);
69+
THROW3(m_sound._handle() || m_bIsNoSound, "There is no sound", *m_caSoundToPlay);
6970
m_sound.play_no_feedback((object) ? &object->object() : NULL, flags, delay, &pos, &vol);
7071
}

src/xrGame/script_sound.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CScriptSound
1616
{
1717
mutable ref_sound m_sound;
1818
shared_str m_caSoundToPlay;
19+
bool m_bIsNoSound = false;
1920

2021
friend class CScriptSoundAction;
2122

src/xrGame/script_sound_inline.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
IC u32 CScriptSound::Length()
1212
{
13-
VERIFY(m_sound._handle());
13+
VERIFY(m_sound._handle() || m_bIsNoSound);
1414
return iFloor(m_sound.get_length_sec() * 1000.0f);
1515
}
1616

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

2929
IC void CScriptSound::SetMinDistance(const float fMinDistance)
3030
{
31-
VERIFY(m_sound._handle());
31+
VERIFY(m_sound._handle() || m_bIsNoSound);
3232
m_sound.set_range(fMinDistance, GetMaxDistance());
3333
}
3434

3535
IC void CScriptSound::SetMaxDistance(const float fMaxDistance)
3636
{
37-
VERIFY(m_sound._handle());
37+
VERIFY(m_sound._handle() || m_bIsNoSound);
3838
m_sound.set_range(GetMinDistance(), fMaxDistance);
3939
}
4040

4141
IC const float CScriptSound::GetFrequency() const
4242
{
43-
VERIFY(m_sound._handle());
43+
VERIFY(m_sound._handle() || m_bIsNoSound);
4444
return (m_sound.get_params()->freq);
4545
}
4646

4747
IC const float CScriptSound::GetMinDistance() const
4848
{
49-
VERIFY(m_sound._handle());
49+
VERIFY(m_sound._handle() || m_bIsNoSound);
5050
return (m_sound.get_params()->min_distance);
5151
}
5252

5353
IC const float CScriptSound::GetMaxDistance() const
5454
{
55-
VERIFY(m_sound._handle());
55+
VERIFY(m_sound._handle() || m_bIsNoSound);
5656
return (m_sound.get_params()->max_distance);
5757
}
5858

5959
IC const float CScriptSound::GetVolume() const
6060
{
61-
VERIFY(m_sound._handle());
61+
VERIFY(m_sound._handle() || m_bIsNoSound);
6262
return (m_sound.get_params()->volume);
6363
}
6464

@@ -72,42 +72,42 @@ IC bool CScriptSound::IsPlaying() const
7272
IC void CScriptSound::AttachTail(LPCSTR caSoundName) { m_sound.attach_tail(caSoundName); }
7373
IC void CScriptSound::Stop()
7474
{
75-
VERIFY(m_sound._handle());
75+
VERIFY(m_sound._handle() || m_bIsNoSound);
7676
m_sound.stop();
7777
}
7878

7979
IC void CScriptSound::StopDeferred()
8080
{
81-
VERIFY(m_sound._handle());
81+
VERIFY(m_sound._handle() || m_bIsNoSound);
8282
m_sound.stop_deferred();
8383
}
8484

8585
IC void CScriptSound::SetPosition(const Fvector& position)
8686
{
87-
VERIFY(m_sound._handle());
87+
VERIFY(m_sound._handle() || m_bIsNoSound);
8888
m_sound.set_position(position);
8989
}
9090

9191
IC void CScriptSound::SetFrequency(float frequency)
9292
{
93-
VERIFY(m_sound._handle());
93+
VERIFY(m_sound._handle() || m_bIsNoSound);
9494
m_sound.set_frequency(frequency);
9595
}
9696

9797
IC void CScriptSound::SetVolume(float volume)
9898
{
99-
VERIFY(m_sound._handle());
99+
VERIFY(m_sound._handle() || m_bIsNoSound);
100100
m_sound.set_volume(volume);
101101
}
102102

103103
IC const CSound_params* CScriptSound::GetParams()
104104
{
105-
VERIFY(m_sound._handle());
105+
VERIFY(m_sound._handle() || m_bIsNoSound);
106106
return (m_sound.get_params());
107107
}
108108

109109
IC void CScriptSound::SetParams(CSound_params* sound_params)
110110
{
111-
VERIFY(m_sound._handle());
111+
VERIFY(m_sound._handle() || m_bIsNoSound);
112112
m_sound.set_params(sound_params);
113113
}

src/xrGame/ui/UIComboBox.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,23 @@ void CUIComboBox::SetCurrentOptValue()
123123
m_list_box.Clear();
124124
const xr_token* tok = GetOptToken();
125125

126-
while (tok->name)
126+
if (tok)
127127
{
128-
if (m_disabled.end() == std::find(m_disabled.begin(), m_disabled.end(), tok->id))
128+
while (tok->name)
129129
{
130-
AddItem_(tok->name, tok->id);
130+
if (m_disabled.end() == std::find(m_disabled.begin(), m_disabled.end(), tok->id))
131+
{
132+
AddItem_(tok->name, tok->id);
133+
}
134+
tok++;
131135
}
132-
tok++;
133-
}
134136

135-
LPCSTR cur_val = *CStringTable().translate(GetOptTokenValue());
136-
m_text.SetText(cur_val);
137-
m_list_box.SetSelectedText(cur_val);
137+
LPCSTR cur_val = *CStringTable().translate(GetOptTokenValue());
138+
m_text.SetText(cur_val);
139+
m_list_box.SetSelectedText(cur_val);
140+
}
141+
else
142+
m_text.SetText("-");
138143

139144
CUIListBoxItem* itm = m_list_box.GetSelectedItem();
140145
if (itm)

src/xrGame/ui/UIGameTutorialVideoItem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void CUISequenceVideoItem::Load(CUIXml* xml, int idx)
9393
if (snd_name && snd_name[0])
9494
{
9595
m_sound.create(snd_name, st_Effect, sg_Undefined);
96-
VERIFY(m_sound._handle());
96+
VERIFY(m_sound._handle() || strstr(Core.Params, "-nosound"));
9797
}
9898
xml->SetLocalRoot(_stored_root);
9999
}

0 commit comments

Comments
 (0)