Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cf5d166

Browse files
Pirulaxbotder
andauthored
Improve setSoundEffectParameters error messages (PR #2552)
* Add better error handling to setSoundEffectParams * Finish * Use SString for formatting Lua error (as luaL_error crashes) * Add `BASS_ERROR_DENIED` error code * Apply suggestions from code review * Update Client/mods/deathmatch/logic/CBassAudio.cpp Co-authored-by: Marek Kulik <me@botder.com>
1 parent 716dd6c commit cf5d166

File tree

3 files changed

+519
-427
lines changed

3 files changed

+519
-427
lines changed

‎Client/mods/deathmatch/logic/CBassAudio.cpp‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,107 @@ bool CBassAudio::BeginLoadingMedia()
237237
return true;
238238
}
239239

240+
const char* CBassAudio::ErrorGetMessage() {
241+
// As BASS has no function to retrieve the error messages we must do it manually
242+
// So this should be kept updated
243+
// Error messages copied directly from BASS
244+
switch (ErrorGetCode()) {
245+
case BASS_OK:
246+
return "all is OK";
247+
case BASS_ERROR_MEM:
248+
return "memory error";
249+
case BASS_ERROR_FILEOPEN:
250+
return "can't open the file";
251+
case BASS_ERROR_DRIVER:
252+
return "can't find a free/valid driver";
253+
case BASS_ERROR_BUFLOST:
254+
return "the sample buffer was lost";
255+
case BASS_ERROR_HANDLE:
256+
return "invalid handle";
257+
case BASS_ERROR_FORMAT:
258+
return "unsupported sample format";
259+
case BASS_ERROR_POSITION:
260+
return "invalid position";
261+
case BASS_ERROR_INIT:
262+
return "BASS_Init has not been successfully called";
263+
case BASS_ERROR_START:
264+
return "BASS_Start has not been successfully called";
265+
case BASS_ERROR_SSL:
266+
return "SSL/HTTPS support isn't available";
267+
case BASS_ERROR_REINIT:
268+
return "device needs to be reinitialized";
269+
case BASS_ERROR_ALREADY:
270+
return "already initialized/paused/whatever";
271+
case BASS_ERROR_NOTAUDIO:
272+
return "file does not contain audio";
273+
case BASS_ERROR_NOCHAN:
274+
return "can't get a free channel";
275+
case BASS_ERROR_ILLTYPE:
276+
return "an illegal type was specified";
277+
case BASS_ERROR_ILLPARAM:
278+
return "an illegal parameter was specified";
279+
case BASS_ERROR_NO3D:
280+
return "no 3D support";
281+
case BASS_ERROR_NOEAX:
282+
return "no EAX support";
283+
case BASS_ERROR_DEVICE:
284+
return "illegal device number";
285+
case BASS_ERROR_NOPLAY:
286+
return "not playing";
287+
case BASS_ERROR_FREQ:
288+
return "illegal sample rate";
289+
case BASS_ERROR_NOTFILE:
290+
return "the stream is not a file stream";
291+
case BASS_ERROR_NOHW:
292+
return "no hardware voices available";
293+
case BASS_ERROR_EMPTY:
294+
return "the file has no sample data";
295+
case BASS_ERROR_NONET:
296+
return "no internet connection could be opened";
297+
case BASS_ERROR_CREATE:
298+
return "couldn't create the file";
299+
case BASS_ERROR_NOFX:
300+
return "effects are not available";
301+
case BASS_ERROR_NOTAVAIL:
302+
return "requested data/action is not available";
303+
case BASS_ERROR_DECODE:
304+
return "the channel is/isn't a \"decoding channel\"";
305+
case BASS_ERROR_DX:
306+
return "a sufficient DirectX version is not installed";
307+
case BASS_ERROR_TIMEOUT:
308+
return "connection timedout";
309+
case BASS_ERROR_FILEFORM:
310+
return "unsupported file format";
311+
case BASS_ERROR_SPEAKER:
312+
return "unavailable speaker";
313+
case BASS_ERROR_VERSION:
314+
return "invalid BASS version (used by add-ons)";
315+
case BASS_ERROR_CODEC:
316+
return "codec is not available/supported";
317+
case BASS_ERROR_ENDED:
318+
return "the channel/file has ended";
319+
case BASS_ERROR_BUSY:
320+
return "the device is busy";
321+
case BASS_ERROR_UNSTREAMABLE:
322+
return "unstreamable file";
323+
case BASS_ERROR_PROTOCOL:
324+
return "unsupported protocol";
325+
case BASS_ERROR_DENIED:
326+
return "access denied";
327+
case BASS_ERROR_UNKNOWN:
328+
return "some other mystery problem";
329+
330+
// BASS may add new error codes in the future, which must be appended to the switch above.
331+
// Also, add-ons may introduce additional error codes.
332+
default:
333+
return "unknown error (?)";
334+
}
335+
}
336+
337+
int CBassAudio::ErrorGetCode() {
338+
return BASS_ErrorGetCode();
339+
}
340+
240341
//
241342
// Util use in BeginLoadingMedia
242343
//

‎Client/mods/deathmatch/logic/CBassAudio.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ class CBassAudio
9494
float GetSoundBPM();
9595
void SetSoundBPM(float fBPM) { m_fBPM = fBPM; }
9696

97+
// Retrieves the error message for the most recent BASS function call in the current thread.
98+
static const char* ErrorGetMessage();
99+
100+
// Retrieves the error code for the most recent BASS function call in the current thread.
101+
static int ErrorGetCode();
102+
97103
protected:
98104
HSTREAM ConvertFileToMono(const SString& strPath);
99105
static DWORD WINAPI PlayStreamIntern(LPVOID argument);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /