我在cocos2d-x3.3 版本中测试了 新引入的音频模块。 自己写了个测试文件 然后多次重复点击。差不多点击30次左右 出现Too Many Objects错误。 我以为是我代码没释放资源的问题。然后去找 发现没有相关的函数。有个remove还是protected的。 然后 我音频播放结束的回调里面加上 stop 还是出现这个问题。
然后我去用官方提供的样例 也方向有同样的问题。 请问这个如何解决呢?
我的:
AudioProfile _audioProfile;
_audioProfile.name = "AudioProfile";
_audioProfile.maxInstances = 3;
_audioProfile.minDelay = 0.1;
int audioId = AudioEngine::play2d(musicPath.c_str(), isLoop, 0.5f, &_audioProfile);
AudioEngine::setFinishCallback(audioId, &](int audioId, const std::string& path)
{
audioId = AudioEngine::INVAILD_AUDIO_ID;
});
```
出现如下错误
官方的:
_audioProfile.name = "AudioProfileTest";
_audioProfile.maxInstances = 300;
_audioProfile.minDelay = 1.0;
Vec2 pos(0.5f,0.7f);
for(int index = 0; index < FILE_COUNT; ++index){
sprintf(text,"play %s",_files.c_str());
auto playItem = TextButton::create(text, &](TextButton* button){
int index = button->getTag();
auto id = AudioEngine::play2d(_files, false, 1.0f, &_audioProfile);
if(id != AudioEngine::INVAILD_AUDIO_ID){
_time = _minDelay;
_audioCount += 1;
char show;
sprintf(show,"audio count:%d",_audioCount);
_showLabel->setString(show);
AudioEngine::setFinishCallback(id, &](int id, const std::string& filePath){
_audioCount -= 1;
char show;
sprintf(show,"audio count:%d",_audioCount);
_showLabel->setString(show);
});
}
});
```
出现如下:

