You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey folks, posting what looks like a small code oversight/error due to legacy bugs and recent refactors.
But I wanted to first confirm some early behaviours before making a patch.
Uncaught TypeError: Cannot read properties of null (reading 'fileComplete')
Firefox:
Uncaught TypeError: _this.game.load is null
What's the error trace (expand the error message)?
from videoLoadEvent
Cause
The affected line errors when the game instance is destroyed before any video preloading has completed.
The demo link has more detailed setup code, but its basically this:
Since the game is destroyed before the video's videoLoadEvent callback is fired, when it eventually runs, the _this.game.load reference no longer exists, and errors.
History
I was snooping through the git history, as it looked odd that the video callback would reference it like _this.game.load.fileComplete instead of _this.fileComplete (like the audio tag callback).
It appears to be from an early bug (added in this commit):
The original code and comment suggests that there was an early browser bug which required the latest GAMES instance to be used instead of just the current Loader instance (this). Since the code is now this.game.load.fileComplete, isn't that the same as this.fileComplete? i.e. the original bug may no longer exist (but I wonder if @photonstorm can recall why that was needed)
The recent refactor to change it from Phaser.GAMES[_this.game.id] to _this.game looks like we can potentially now just match the audio callbacks and use _this.fileComplete directly?
Hey folks, posting what looks like a small code oversight/error due to legacy bugs and recent refactors.
But I wanted to first confirm some early behaviours before making a patch.
This Issue is about A bug in the API.
Phaser version(s): Phaser-CE 2.20.0
Live example: https://blake.pp.ua/loadVideoTag/
What steps produce the bug: (See below)
What's the error message?
Chrome:
Firefox:
What's the error trace (expand the error message)?
from videoLoadEvent
Cause
The affected line errors when the
game
instance is destroyed before any video preloading has completed.The demo link has more detailed setup code, but its basically this:
Since the
game
is destroyed before the video's videoLoadEvent callback is fired, when it eventually runs, the_this.game.load
reference no longer exists, and errors.History
I was snooping through the git history, as it looked odd that the video callback would reference it like
_this.game.load.fileComplete
instead of_this.fileComplete
(like the audio tag callback).It appears to be from an early bug (added in this commit):
phaser-ce/src/loader/Loader.js
Lines 2053 to 2054 in 77468e7
That comment was then removed here: 7d308a2
And in a more recent update was refactored here (10ef4b2) to be:
phaser-ce/src/loader/Loader.js
Line 2643 in 10ef4b2
(which is the current 2.20.0 version)
Potential fix
The original code and comment suggests that there was an early browser bug which required the latest
GAMES
instance to be used instead of just the current Loader instance (this
). Since the code is nowthis.game.load.fileComplete
, isn't that the same asthis.fileComplete
? i.e. the original bug may no longer exist (but I wonder if @photonstorm can recall why that was needed)The recent refactor to change it from
Phaser.GAMES[_this.game.id]
to_this.game
looks like we can potentially now just match the audio callbacks and use_this.fileComplete
directly?i.e. this line could now be:
This prevents the error since
fileComplete
method already handles if the game is destroyed.Demo link: https://blake.pp.ua/loadVideoTag2/
If this isn't ideal, or we don't want to potentially break it, could we just add a guard?
The text was updated successfully, but these errors were encountered: