Skip to content
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

Before music initialization, call setEffectsVolume will caused an Error---this.music is null #16981

Open
tangkaikk opened this issue May 13, 2024 · 0 comments
Assignees
Labels
Bug Needs Triage Needs to be assigned by the team

Comments

@tangkaikk
Copy link

tangkaikk commented May 13, 2024

Cocos Creator version

2.4.12, 2.4.13

System information

taobaominigame simulator

Issue description

error:
Uncaught TypeError: Cannot read properties of null (reading 'id')
at Object.setEffectsVolume (adapter.js:6947:26)
at audio.setEffectVolume (index.js:126:24)
at proto.emit (cocos2d-js.js:42020:12)
at _Class2.emit (cocos2d-js.js:16212:7)
at _Class2._emitSlideEvent (cocos2d-js.js:30158:7)
at _Class2._handleSliderLogic (cocos2d-js.js:30154:7)
at _Class2._onTouchMoved (cocos2d-js.js:30139:9)
at proto.emit (cocos2d-js.js:42020:12)
at _doDispatchEvent (cocos2d-js.js:15347:56)
at _Class2.dispatchEvent (cocos2d-js.js:16216:9)

code:
setEffectsVolume: function setEffectsVolume(volume) {
volume = handleVolume(volume);
var musicId = this._music.id;
this._effectVolume = volume;

for (var id in _id2audio) {
  var audio = _id2audio[id];
  if (!audio || audio.id === musicId) continue;
  audio.setVolume(volume);
}

},

Reason:
Before music initialization, i called setEffectsVolume , and then caused the Error. I found that there was an object this._music was null. and I changed the code from "this._music.id;" to "this._music.id?this._music.id:-1;", the error had dissappear.

Relevant error log output

Uncaught TypeError: Cannot read properties of null (reading 'id') at Object.setEffectsVolume (adapter.js:6947:26) at audio.setEffectVolume (index.js:126:24) at proto.emit (cocos2d-js.js:42020:12) at _Class2.emit (cocos2d-js.js:16212:7) at _Class2._emitSlideEvent (cocos2d-js.js:30158:7) at _Class2._handleSliderLogic (cocos2d-js.js:30154:7) at _Class2._onTouchMoved (cocos2d-js.js:30139:9) at proto.emit (cocos2d-js.js:42020:12) at _doDispatchEvent (cocos2d-js.js:15347:56) at _Class2.dispatchEvent (cocos2d-js.js:16216:9)
  | setEffectsVolume | @ | adapter.js:6947 -- | -- | -- | --   | audio.setEffectVolume | @ | index.js:126   | proto.emit | @ | cocos2d-js.js:42020   | emit | @ | cocos2d-js.js:16212   | _emitSlideEvent | @ | cocos2d-js.js:30158   | _handleSliderLogic | @ | cocos2d-js.js:30154   | _onTouchMoved | @ | cocos2d-js.js:30139   | proto.emit | @ | cocos2d-js.js:42020   | _doDispatchEvent | @ | cocos2d-js.js:15347   | dispatchEvent | @ | cocos2d-js.js:16216   | _touchMoveHandler | @ | cocos2d-js.js:15228   | _onTouchEventCallback | @ | cocos2d-js.js:32783   | _dispatchEventToListeners | @ | cocos2d-js.js:32871   | _dispatchTouchEvent | @ | cocos2d-js.js:32820   | dispatchEvent | @ | cocos2d-js.js:33072   | handleTouchesMove | @ | cocos2d-js.js:39874   | (anonymous) | @ | adapter.js:1342   | (anonymous) | @ | vuedomapi.js:2   | F.moveListener | @ | vuedomapi.js:2   | dispatchEvent | @ | adapter.js:5907   | canvas1.dispatchEvent | @ | adapter.js:4794   | triggerTouch | @ | unknown   | (anonymous) | @ | unknown

Steps to reproduce

1.launch application 2,slide the slider

Minimal reproduction project

audio error demo.zip

@tangkaikk tangkaikk added Bug Needs Triage Needs to be assigned by the team labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Needs to be assigned by the team
Projects
None yet
Development

No branches or pull requests

2 participants