We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3662 - Error message when using the audio conversion setup without an initialized audio subsystem is a bit vague
Summary: Error message when using the audio conversion setup without an initialized au...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: audio (show other bugs)
Version: HG 2.0
Hardware: All All
: P2 trivial
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.6
Depends on:
Blocks:
 
Reported: 2017-06-05 23:09 UTC by Simon Hug
Modified: 2017-08-29 16:02 UTC (History)
1 user (show)

See Also:


Attachments
Patch that increases the verbosity on the requirement of an initialized subsystem when using the audio conversion setup. (2.14 KB, patch)
2017-06-05 23:09 UTC, Simon Hug
Details | Diff
Test program for the uninitialized audio subsystem error messages. (2.44 KB, text/plain)
2017-06-05 23:11 UTC, Simon Hug
Details
Patch that adds a check for an initialized audio subsystem to SDL_BuildAudioCVT. Also changes some comments and error messages to reflect the implementation better. (3.00 KB, patch)
2017-06-06 15:36 UTC, Simon Hug
Details | Diff
Revised test program for the uninitialized audio subsystem error messages. (2.67 KB, text/plain)
2017-06-06 15:39 UTC, Simon Hug
Details
Patch that corrects documentation. (586 bytes, patch)
2017-08-29 11:23 UTC, Simon Hug
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hug 2017-06-05 23:09:05 UTC
Created attachment 2750 [details]
Patch that increases the verbosity on the requirement of an initialized subsystem when using the audio conversion setup.

The audio conversion which go from, to, or over the floating point format currently require the audio subsystem to be initialized. The error message that gets returned by SDL_GetError after SDL_BuildAudioCVT has failed because of a uninitialized audio subsystem is a bit vague about this.

The attached patch increases the verbosity on this requirement in the documentation and error messages.
Comment 1 Simon Hug 2017-06-05 23:11:36 UTC
Created attachment 2751 [details]
Test program for the uninitialized audio subsystem error messages.

Attaching a program that tries to use the audio conversion without initializing the SDL audio subsystem and then displays the error messages.
Comment 2 Ryan C. Gordon 2017-06-06 05:06:44 UTC
Maybe it's better to report an error immediately if the audio subsystem isn't initialized.

--ryan.
Comment 3 Simon Hug 2017-06-06 15:36:16 UTC
Created attachment 2752 [details]
Patch that adds a check for an initialized audio subsystem to SDL_BuildAudioCVT. Also changes some comments and error messages to reflect the implementation better.

Something like this? There's the small detail that the conversion functions don't get set to NULL on SDL_AudioQuit and the check now blocks it from working, but I'm guessing no one will really expect them to in this scenario.

I also noticed that SDL_BuildAudioCVT seems to accept negative sample rates. Is this intentional?
Comment 4 Simon Hug 2017-06-06 15:39:22 UTC
Created attachment 2753 [details]
Revised test program for the uninitialized audio subsystem error messages.

I noticed that the previous program had bugs. It now also retries all steps after calling SDL_Quit once.
Comment 5 Ryan C. Gordon 2017-08-09 05:25:35 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.6.

This means we're in the final stretch for an official SDL 2.0.6 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.6 release, and generally be organized about what we're aiming to ship. After some debate, we might just remove this tag again and deal with it for a later release.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 6 Ryan C. Gordon 2017-08-18 20:52:45 UTC

This patch is now https://hg.libsdl.org/SDL/rev/86b1fde471c6, thanks!

--ryan.
Comment 7 trondah 2017-08-28 14:01:08 UTC
This change causes Emulationstation to segmentation fault (some times terminates due to std:alloc). Does that mean something needs to be fixed in Emulationstation? Works fine with this reversed.
Comment 8 Simon Hug 2017-08-28 15:09:07 UTC
After a very quick look at the code: Yes, there is a bug in the EmulationStation code.

There's no check for errors after a call to SDL_BuildAudioCVT. If an error occurs, I think it's possible that it allocates memory of an undefined size.

https://github.com/Aloshi/EmulationStation/blob/646bede3d9ec0acf0ae378415edac136774a66c5/es-core/src/Sound.cpp#L69

I'm not sure why that would happen after this specific change. There's an SDL_InitSubSystem call in the AudioManager::init function. Does it not get properly called?
Comment 9 trondah 2017-08-28 17:35:47 UTC
I can't really tell, as I'm not a developer. Emulationstation isn't developed anymore either, except for RetroPie's fork. Perhaps they will fix it down the road, until then I can just revert this change as it works fine for me without it. Sorry to bother everyone :)
Comment 10 Simon Hug 2017-08-28 22:28:35 UTC
No bother at all. It's important to know how existing projects using SDL2 behave.

I created a bug report on their GitHub issue tracker.

https://github.com/RetroPie/EmulationStation/issues/230

Would you be able to test it should anyone ever have the time to make some changes? No commitment required, of course. ;)

This issue actually raises the question if this API change (requirement of initialized audio subsystem) is breaking backwards compatibility. I don't see the documentation saying it is needed in 2.0.5.
Comment 11 Sam Lantinga 2017-08-29 00:17:58 UTC
We really shouldn't require audio device initialization for converting audio in place.

I'll take a look at that.
Comment 12 Sam Lantinga 2017-08-29 04:43:46 UTC
Fixed!
https://hg.libsdl.org/SDL/rev/f40c2dedaded
Comment 13 Ryan C. Gordon 2017-08-29 04:54:15 UTC
(In reply to Sam Lantinga from comment #11)
> We really shouldn't require audio device initialization for converting audio
> in place.

I'm okay with this working either way, but I don't think it's unreasonable to think of SDL_Init() as initializing subsystems as a whole and require it even if you don't plan to playback or record audio.

I mention this because calling SDL_ChooseAudioConverters could be a race condition if you have multiple threads converting audio, so it was nice to require explicit init so this would definitely be set up by the time converters need it.

--ryan.
Comment 14 Sam Lantinga 2017-08-29 05:03:25 UTC
The race condition should be pointers getting overwritten with the same values, so I'm okay with this. I'd hate to break applications that aren't expecting this change.
Comment 15 trondah 2017-08-29 11:04:38 UTC
(In reply to Sam Lantinga from comment #12)
> Fixed!
> https://hg.libsdl.org/SDL/rev/f40c2dedaded

This solves it for me :)
Comment 16 Simon Hug 2017-08-29 11:23:26 UTC
Created attachment 2899 [details]
Patch that corrects documentation.

The documentation should also be adjusted again. Attached patch does that.
Comment 17 Sam Lantinga 2017-08-29 16:02:27 UTC
Got it, thanks!
https://hg.libsdl.org/SDL/rev/41bc8b8e9758