-
Notifications
You must be signed in to change notification settings - Fork 260
fix(SRP): crash when native OpenAL is unavailable #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
21cef2b
bb5488e
74de52b
864330e
6eb4a14
05029c9
5bd54e1
c3ef7a6
d8593c5
d9119a3
a2d2162
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,9 @@ unsigned int AudioEngine::sMaxInstances = MAX_AUDIOINSTANCES; | |
| AudioEngine::ProfileHelper *AudioEngine::sDefaultProfileHelper = nullptr; | ||
| ccstd::unordered_map<int, AudioEngine::AudioInfo> AudioEngine::sAudioIDInfoMap; | ||
| AudioEngineImpl *AudioEngine::sAudioEngineImpl = nullptr; | ||
| // Decoder-only fallback instance, defined here to keep AudioDecoderManager | ||
| // initialization separate from OpenAL initialization. | ||
| AudioEngineImpl *AudioEngine::sDecoderImpl = nullptr; | ||
|
|
||
| float AudioEngine::sVolumeFactor = 1.0F; | ||
| events::EnterBackground::Listener AudioEngine::sOnPauseListenerID; | ||
|
|
@@ -156,6 +159,9 @@ void AudioEngine::end() { | |
| delete sAudioEngineImpl; | ||
| sAudioEngineImpl = nullptr; | ||
|
|
||
| delete sDecoderImpl; | ||
| sDecoderImpl = nullptr; | ||
|
|
||
| delete sDefaultProfileHelper; | ||
| sDefaultProfileHelper = nullptr; | ||
|
|
||
|
|
@@ -587,12 +593,48 @@ bool AudioEngine::isEnabled() { | |
| return sIsEnabled; | ||
| } | ||
|
|
||
| AudioEngineImpl *AudioEngine::getDecoderImpl() { | ||
| if (AudioEngine::sAudioEngineImpl != nullptr) { | ||
| return AudioEngine::sAudioEngineImpl; | ||
| } | ||
| // Try full init first; if it succeeds we get OpenAL + decoder. | ||
| AudioEngine::lazyInit(); | ||
| if (AudioEngine::sAudioEngineImpl != nullptr) { | ||
| return AudioEngine::sAudioEngineImpl; | ||
| } | ||
| // On oalsoft platforms, PCM decoding via AudioDecoderManager works | ||
| // independently of OpenAL — create a decoder-only fallback instance. | ||
| // On Android/OpenHarmony and Apple, AudioEngineImpl::getPCMHeader/ | ||
| // getOriginalPCMBuffer dereferences _audioPlayerProvider/_engineEngine | ||
| // which are only set up by init(). Returning nullptr here lets callers | ||
| // fail gracefully instead of crashing. | ||
| #if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_OHOS || \ | ||
| CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX | ||
| if (AudioEngine::sDecoderImpl == nullptr) { | ||
| AudioEngine::sDecoderImpl = ccnew AudioEngineImpl(); | ||
| AudioEngineImpl::initDecoder(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to make initDecoder() a non-static member function?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think keep static member function will be batter. Called independently without relying on a full OpenAL initialization
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it |
||
| } | ||
| return AudioEngine::sDecoderImpl; | ||
| #else | ||
| return nullptr; | ||
| #endif | ||
| } | ||
|
|
||
| PCMHeader AudioEngine::getPCMHeader(const char *url) { | ||
| lazyInit(); | ||
| return sAudioEngineImpl->getPCMHeader(url); | ||
| AudioEngineImpl *impl = AudioEngine::getDecoderImpl(); | ||
| if (impl == nullptr) { | ||
| CC_LOG_WARNING("AudioEngine::getPCMHeader: audio engine unavailable, url: %s", url); | ||
| return {}; | ||
| } | ||
| return impl->getPCMHeader(url); | ||
| } | ||
|
|
||
| ccstd::vector<uint8_t> AudioEngine::getOriginalPCMBuffer(const char *url, uint32_t channelID) { | ||
| lazyInit(); | ||
| return sAudioEngineImpl->getOriginalPCMBuffer(url, channelID); | ||
| AudioEngineImpl *impl = AudioEngine::getDecoderImpl(); | ||
| if (impl == nullptr) { | ||
| CC_LOG_WARNING("AudioEngine::getOriginalPCMBuffer: audio engine unavailable, url: %s", url); | ||
| return {}; | ||
| } | ||
| return impl->getOriginalPCMBuffer(url, channelID); | ||
| } | ||
| } // namespace cc | ||
Uh oh!
There was an error while loading. Please reload this page.