Merge pull request #16228 from dumganhar/fix/iss14148-ios-no-sound

fixed #14148: Got an error while pressing home button at launch, after resuming from background, SimpileAudioEngine::playEffect will be mute.
This commit is contained in:
minggo 2016-07-29 09:28:37 +08:00 committed by GitHub
commit a8ce513f6c
1 changed files with 23 additions and 12 deletions

View File

@ -353,18 +353,9 @@ static BOOL _mixerRateSet = NO;
free(defs); free(defs);
} }
- (id)init - (void) _lazyInitOpenAL
{ {
if ((self = [super init])) { if (!functioning_) {
//Create mutexes
_mutexBufferLoad = [[NSObject alloc] init];
asynchLoadProgress_ = 0.0f;
bufferTotal = CD_BUFFERS_START;
_buffers = (bufferInfo *)malloc( sizeof(_buffers[0]) * bufferTotal);
// Initialize our OpenAL environment // Initialize our OpenAL environment
if ([self _initOpenAL]) { if ([self _initOpenAL]) {
//Set up the default source group - a single group that contains all the sources //Set up the default source group - a single group that contains all the sources
@ -379,11 +370,29 @@ static BOOL _mixerRateSet = NO;
enabled_ = YES; enabled_ = YES;
//Test whether get gain works for sources //Test whether get gain works for sources
[self _testGetGain]; [self _testGetGain];
CDLOG(@"OpenAL was initialized successfully!");
} else { } else {
//Something went wrong with OpenAL //Something went wrong with OpenAL
functioning_ = NO; functioning_ = NO;
CDLOG(@"OpenAL failed to be initialized!");
} }
} }
}
- (id)init
{
if ((self = [super init])) {
//Create mutexes
_mutexBufferLoad = [[NSObject alloc] init];
asynchLoadProgress_ = 0.0f;
bufferTotal = CD_BUFFERS_START;
_buffers = (bufferInfo *)malloc( sizeof(_buffers[0]) * bufferTotal);
[self _lazyInitOpenAL];
}
return self; return self;
} }
@ -506,6 +515,8 @@ static BOOL _mixerRateSet = NO;
@synchronized(_mutexBufferLoad) { @synchronized(_mutexBufferLoad) {
[self _lazyInitOpenAL];
if (!functioning_) { if (!functioning_) {
//OpenAL initialisation has previously failed //OpenAL initialisation has previously failed
CDLOG(@"Denshion::CDSoundEngine - Loading buffer failed because sound engine state != functioning"); CDLOG(@"Denshion::CDSoundEngine - Loading buffer failed because sound engine state != functioning");