Merge lp:~widelands-dev/widelands/bug-1743086-sdl-sound-bug-workaround into lp:widelands

Proposed by Klaus Halfmann
Status: Merged
Merged at revision: 8662
Proposed branch: lp:~widelands-dev/widelands/bug-1743086-sdl-sound-bug-workaround
Merge into: lp:widelands
Diff against target: 281 lines (+85/-31)
4 files modified
src/sound/sound_handler.cc (+42/-11)
src/sound/sound_handler.h (+7/-6)
src/ui_fsmenu/options.cc (+9/-2)
src/wui/game_options_sound_menu.cc (+27/-12)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1743086-sdl-sound-bug-workaround
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+343764@code.launchpad.net

Commit message

Workaround for Bug 1743086, completly disable sound in this case.

Test this on "Linux Budgie 4.13.0-38-generic #43-Ubuntu SMP Wed Mar 14 15:20:44 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux" works as expected

Description of the change

Actually Done by GunChleoc:

Set a special flag that completly disables any sound, despite any user settigns, adds some log- and warning- messages to inform the User about this.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3397. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/369740569.
Appveyor build 3203. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1743086_sdl_sound_bug_workaround-3203.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for testing! :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sound/sound_handler.cc'
2--- src/sound/sound_handler.cc 2018-04-07 16:59:00 +0000
3+++ src/sound/sound_handler.cc 2018-04-22 11:58:26 +0000
4@@ -66,7 +66,7 @@
5 */
6 SoundHandler::SoundHandler()
7 : nosound_(false),
8- lock_audio_disabling_(false),
9+ is_backend_disabled_(false),
10 disable_music_(false),
11 disable_fx_(false),
12 music_volume_(MIX_MAX_VOLUME),
13@@ -100,10 +100,33 @@
14 const uint16_t bufsize = 1024;
15 #endif
16
17+ SDL_version sdl_version;
18+ SDL_GetVersion(&sdl_version);
19+ log("**** SOUND REPORT ****\n");
20+ log("SDL version: %d.%d.%d\n",
21+ static_cast<unsigned int>(sdl_version.major),
22+ static_cast<unsigned int>(sdl_version.minor),
23+ static_cast<unsigned int>(sdl_version.patch));
24+
25+ /// SDL 2.0.6 will crash due to upstream bug:
26+ /// https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1722060
27+ if (sdl_version.major == 2 && sdl_version.minor == 0 && sdl_version.patch == 6) {
28+ log("Disabled sound due to a bug in SDL 2.0.6\n");
29+ nosound_ = true;
30+ }
31+
32+ SDL_MIXER_VERSION(&sdl_version);
33+ log("SDL_mixer version: %d.%d.%d\n",
34+ static_cast<unsigned int>(sdl_version.major),
35+ static_cast<unsigned int>(sdl_version.minor),
36+ static_cast<unsigned int>(sdl_version.patch));
37+
38+ log("**** END SOUND REPORT ****\n");
39+
40 if (nosound_) {
41 set_disable_music(true);
42 set_disable_fx(true);
43- lock_audio_disabling_ = true;
44+ is_backend_disabled_ = true;
45 return;
46 }
47
48@@ -144,7 +167,7 @@
49
50 set_disable_music(true);
51 set_disable_fx(true);
52- lock_audio_disabling_ = true;
53+ is_backend_disabled_ = true;
54 return;
55 }
56
57@@ -225,6 +248,13 @@
58 load_fx_if_needed("sound", "lobby_freshmen", "lobby_freshmen");
59 }
60
61+/**
62+ * Returns 'true' if the playing of sounds is disabled due to sound driver problems.
63+ */
64+bool SoundHandler::is_backend_disabled() const {
65+ return is_backend_disabled_;
66+}
67+
68 /** Load a sound effect. One sound effect can consist of several audio files
69 * named EFFECT_XX.ogg, where XX is between 00 and 99.
70 *
71@@ -269,8 +299,9 @@
72 * until the game is finished.
73 */
74 void SoundHandler::load_one_fx(const std::string& path, const std::string& fx_name) {
75- if (nosound_)
76+ if (nosound_ || is_backend_disabled_) {
77 return;
78+ }
79
80 FileRead fr;
81 if (!fr.try_open(*g_fs, path)) {
82@@ -382,7 +413,7 @@
83 void SoundHandler::play_fx(const std::string& fx_name,
84 int32_t const stereo_pos,
85 uint8_t const priority) {
86- if (nosound_)
87+ if (nosound_ || is_backend_disabled_)
88 return;
89
90 assert(stereo_pos >= -1);
91@@ -432,7 +463,7 @@
92 * finished playing.
93 */
94 void SoundHandler::register_song(const std::string& dir, const std::string& basename) {
95- if (nosound_)
96+ if (nosound_ || is_backend_disabled_)
97 return;
98 assert(g_fs);
99
100@@ -461,7 +492,7 @@
101 * or \ref change_music() this function will block until the fadeout is complete
102 */
103 void SoundHandler::start_music(const std::string& songset_name, int32_t fadein_ms) {
104- if (get_disable_music() || nosound_)
105+ if (get_disable_music() || nosound_ || is_backend_disabled_)
106 return;
107
108 if (fadein_ms == 0)
109@@ -543,7 +574,7 @@
110 * get lost otherwise.
111 */
112 void SoundHandler::set_disable_music(bool const disable) {
113- if (lock_audio_disabling_ || disable_music_ == disable)
114+ if (is_backend_disabled_ || disable_music_ == disable)
115 return;
116
117 if (disable) {
118@@ -562,7 +593,7 @@
119 * get lost otherwise.
120 */
121 void SoundHandler::set_disable_fx(bool const disable) {
122- if (lock_audio_disabling_)
123+ if (is_backend_disabled_)
124 return;
125
126 disable_fx_ = disable;
127@@ -578,7 +609,7 @@
128 * \param volume The new music volume.
129 */
130 void SoundHandler::set_music_volume(int32_t volume) {
131- if (!lock_audio_disabling_ && !nosound_) {
132+ if (!is_backend_disabled_ && !nosound_) {
133 music_volume_ = volume;
134 Mix_VolumeMusic(volume);
135 g_options.pull_section("global").set_int("music_volume", volume);
136@@ -593,7 +624,7 @@
137 * \param volume The new music volume.
138 */
139 void SoundHandler::set_fx_volume(int32_t volume) {
140- if (!lock_audio_disabling_ && !nosound_) {
141+ if (!is_backend_disabled_ && !nosound_) {
142 fx_volume_ = volume;
143 Mix_Volume(-1, volume);
144 g_options.pull_section("global").set_int("fx_volume", volume);
145
146=== modified file 'src/sound/sound_handler.h'
147--- src/sound/sound_handler.h 2018-04-07 16:59:00 +0000
148+++ src/sound/sound_handler.h 2018-04-22 11:58:26 +0000
149@@ -176,6 +176,7 @@
150 void shutdown();
151 void read_config();
152 void load_system_sounds();
153+ bool is_backend_disabled() const;
154
155 void load_fx_if_needed(const std::string& dir,
156 const std::string& basename,
157@@ -220,12 +221,6 @@
158 // TODO(unknown): This is ugly. Find a better way to do it
159 bool nosound_;
160
161- /** Can disable_music_ and disable_fx_ be changed?
162- * true = they mustn't be changed (e.g. because hardware is missing)
163- * false = can be changed at user request
164- */
165- bool lock_audio_disabling_;
166-
167 private:
168 // Prints an error and disables the sound system.
169 void initialization_error(const std::string& msg);
170@@ -233,6 +228,12 @@
171 void load_one_fx(const std::string& path, const std::string& fx_name);
172 bool play_or_not(const std::string& fx_name, int32_t stereo_position, uint8_t priority);
173
174+ /** Can sounds be played?
175+ * true = they mustn't be played (e.g. because hardware is missing)
176+ * false = can be played
177+ */
178+ bool is_backend_disabled_;
179+
180 /// Whether to disable background music
181 bool disable_music_;
182 /// Whether to disable sound effects
183
184=== modified file 'src/ui_fsmenu/options.cc'
185--- src/ui_fsmenu/options.cc 2018-04-07 16:59:00 +0000
186+++ src/ui_fsmenu/options.cc 2018-04-22 11:58:26 +0000
187@@ -259,6 +259,12 @@
188 box_sound_.add(&fx_);
189 box_sound_.add(&message_sound_);
190
191+ if (g_sound_handler.is_backend_disabled()) {
192+ UI::Textarea* sound_warning = new UI::Textarea(&box_sound_, 0, 0, _("Sound is disabled due to a problem with the sound driver"));
193+ sound_warning->set_color(UI_FONT_CLR_WARNING);
194+ box_sound_.add(sound_warning);
195+ }
196+
197 // Saving
198 box_saving_.add(&sb_autosave_);
199 box_saving_.add(&sb_rolling_autosave_);
200@@ -327,10 +333,11 @@
201
202 // Sound options
203 music_.set_state(opt.music);
204- music_.set_enabled(!g_sound_handler.lock_audio_disabling_);
205+ music_.set_enabled(!g_sound_handler.is_backend_disabled());
206 fx_.set_state(opt.fx);
207- fx_.set_enabled(!g_sound_handler.lock_audio_disabling_);
208+ fx_.set_enabled(!g_sound_handler.is_backend_disabled());
209 message_sound_.set_state(opt.message_sound);
210+ message_sound_.set_enabled(!g_sound_handler.is_backend_disabled());
211
212 // Saving options
213 zip_.set_state(opt.zip);
214
215=== modified file 'src/wui/game_options_sound_menu.cc'
216--- src/wui/game_options_sound_menu.cc 2018-04-07 16:59:00 +0000
217+++ src/wui/game_options_sound_menu.cc 2018-04-22 11:58:26 +0000
218@@ -21,6 +21,7 @@
219 #include "base/i18n.h"
220 #include "graphic/graphic.h"
221 #include "sound/sound_handler.h"
222+#include "ui_basic/multilinetextarea.h"
223
224 GameOptionsSoundMenu::GameOptionsSoundMenu(InteractiveGameBase& gb,
225 UI::UniqueWindow::Registry& registry)
226@@ -62,11 +63,36 @@
227 ingame_music.set_state(!g_sound_handler.get_disable_music());
228 ingame_sound.set_state(!g_sound_handler.get_disable_fx());
229
230- if (g_sound_handler.lock_audio_disabling_) { // disabling sound options
231+ uint32_t boxes_width =
232+ kStateboxSize + hspacing() + std::max(ingame_music.get_w(), ingame_sound.get_w());
233+ uint32_t labels_width =
234+ std::max(ingame_music_volume_label.get_w(), ingame_sound_volume_label.get_w());
235+
236+ set_inner_size(std::max(static_cast<uint32_t>(get_inner_w()),
237+ 2 * hmargin() + std::max(boxes_width, labels_width)),
238+ 2 * vmargin() + 2 * (kStateboxSize + vspacing()) + vbigspacing() +
239+ 3 * vspacing() + 2 * slideh() + ingame_music_volume_label.get_h() +
240+ ingame_music_volume_label.get_h());
241+
242+ if (g_sound_handler.is_backend_disabled()) { // disabling sound options
243 ingame_music.set_enabled(false);
244 ingame_sound.set_enabled(false);
245 ingame_music_volume.set_enabled(false);
246 ingame_sound_volume.set_enabled(false);
247+ UI::MultilineTextarea* sound_warning = new UI::MultilineTextarea(
248+ this,
249+ hmargin(),
250+ ingame_sound_volume.get_y() + ingame_sound_volume.get_h() + vspacing(),
251+ get_inner_w() - 2 * hmargin(),
252+ 0,
253+ _("Sound is disabled due to a problem with the sound driver"),
254+ UI::Align::kLeft,
255+ g_gr->images().get("images/ui_basic/but4.png"),
256+ UI::MultilineTextarea::ScrollMode::kNoScrolling);
257+
258+ sound_warning->set_color(UI_FONT_CLR_WARNING);
259+ set_size(get_w(), get_h() + sound_warning->get_h() + vspacing());
260+
261 } else { // initial widget states
262 ingame_music.set_state(!g_sound_handler.get_disable_music());
263 ingame_sound.set_state(!g_sound_handler.get_disable_fx());
264@@ -84,17 +110,6 @@
265 ingame_sound_volume.changedto.connect(
266 boost::bind(&GameOptionsSoundMenu::sound_volume_changed, this, _1));
267
268- uint32_t boxes_width =
269- kStateboxSize + hspacing() + std::max(ingame_music.get_w(), ingame_sound.get_w());
270- uint32_t labels_width =
271- std::max(ingame_music_volume_label.get_w(), ingame_sound_volume_label.get_w());
272-
273- set_inner_size(std::max(static_cast<uint32_t>(get_inner_w()),
274- 2 * hmargin() + std::max(boxes_width, labels_width)),
275- 2 * vmargin() + 2 * (kStateboxSize + vspacing()) + vbigspacing() +
276- 3 * vspacing() + 2 * slideh() + ingame_music_volume_label.get_h() +
277- ingame_music_volume_label.get_h());
278-
279 if (get_usedefaultpos())
280 center_to_parent();
281 }

Subscribers

People subscribed via source and target branches

to status/vote changes: