From 6efcf87b93433a1a3c22f72066640837f74de584 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 27 Jul 2016 15:33:02 +0800 Subject: [PATCH] fixed #14148: Got an error while pressing home button at launch, after resuming from background, SimpileAudioEngine::playEffect will not be mute. The error is: ERROR: [0x19e5fa000] >aurioc> 807: failed: '!pla' (enable 2, outf< 2 ch, 44100 Hz, Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>) --- cocos/audio/ios/CocosDenshion.m | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/cocos/audio/ios/CocosDenshion.m b/cocos/audio/ios/CocosDenshion.m index bd9b93a48e..d026a8ba90 100644 --- a/cocos/audio/ios/CocosDenshion.m +++ b/cocos/audio/ios/CocosDenshion.m @@ -353,18 +353,9 @@ static BOOL _mixerRateSet = NO; free(defs); } -- (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); - +- (void) _lazyInitOpenAL +{ + if (!functioning_) { // Initialize our OpenAL environment if ([self _initOpenAL]) { //Set up the default source group - a single group that contains all the sources @@ -379,11 +370,29 @@ static BOOL _mixerRateSet = NO; enabled_ = YES; //Test whether get gain works for sources [self _testGetGain]; + CDLOG(@"OpenAL was initialized successfully!"); } else { //Something went wrong with OpenAL 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; } @@ -506,6 +515,8 @@ static BOOL _mixerRateSet = NO; @synchronized(_mutexBufferLoad) { + [self _lazyInitOpenAL]; + if (!functioning_) { //OpenAL initialisation has previously failed CDLOG(@"Denshion::CDSoundEngine - Loading buffer failed because sound engine state != functioning");