gopro / forgejs

ForgeJS is a javascript framework that unleashes immersive WebVR experiences.
https://forgejs.org/
Apache License 2.0
239 stars 61 forks source link

Error when initializing a viewer if `window.history.state.scene` isn't defined #166

Closed nstCactus closed 6 years ago

nstCactus commented 6 years ago

When trying to initialize a FORGE.Viewer after messing with window.history, it fails at this line:

https://github.com/gopro/forgejs/blob/b3b33cd71beaba5db57370a8b5ebb87e2d69bb6d/src/system/History.js#L144

and throws the following error:

forge.js:40047 Uncaught TypeError: Cannot read property 'uid' of undefined at FORGE.History._addState (forge.js:40047) at FORGE.History._sceneLoadStartHandler (forge.js:40003) at FORGE.Listener._execute (forge.js:2998) at FORGE.Listener.execute (forge.js:3030) at FORGE.EventDispatcher.dispatch (forge.js:2765) at FORGE.Story._sceneLoadStartHandler (forge.js:3557) at FORGE.Listener._execute (forge.js:2998) at FORGE.Listener.execute (forge.js:3030) at FORGE.EventDispatcher.dispatch (forge.js:2765) at FORGE.Scene.loadStart (forge.js:5319)

Can be fixed by checking if currentState.scene is defined before trying to read from it:

        else if (!currentState.scene || currentState.scene.uid !== newState.scene.uid)