diff --git a/src/core/utils.js b/src/core/utils.js index e76c574..bba87aa 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -155,9 +155,6 @@ export function getOffsetOfPixel( * @return key */ export function getIdFromObject(obj, ident) { - if (!obj) { - return null; - } const ids = Object.keys(obj); for (let i = 0; i < ids.length; i += 1) { const key = ids[i]; diff --git a/src/store/reducers/canvas.js b/src/store/reducers/canvas.js index deec0ac..394a28e 100644 --- a/src/store/reducers/canvas.js +++ b/src/store/reducers/canvas.js @@ -91,7 +91,7 @@ function getCanvasArgs(canvas, prevCoords) { /* * parse url hash and sets view to coordinates * @param canvases Object with all canvas information - * @return incomplete state based on URL + * @return incomplete state based on URL, null if failed */ function getViewFromURL(canvases) { const { hash } = window.location; @@ -102,7 +102,11 @@ function getViewFromURL(canvases) { let canvasId = getIdFromObject(canvases, canvasIdent); if (!canvasId || (!window.ssv?.backupurl && canvases[canvasId].ed)) { canvasId = DEFAULT_CANVAS_ID; - canvasIdent = canvases[DEFAULT_CANVAS_ID].ident; + const canvas = canvases[DEFAULT_CANVAS_ID]; + if (!canvas) { + return null; + } + canvasIdent = canvas.ident; } const is3D = !!canvases[canvasId].v; @@ -129,7 +133,7 @@ function getViewFromURL(canvases) { const initialState = { canvasId: null, canvasIdent: 'xx', - canvases: null, + canvases: {}, canvasSize: 65536, historicalCanvasSize: 65536, is3D: null, @@ -196,10 +200,10 @@ export default function canvasReducer( case 'RELOAD_URL': { const { canvases } = state; - if (!canvases) { + const urlState = getViewFromURL(canvases); + if (!urlState) { return state; } - const urlState = getViewFromURL(canvases); if (urlState.canvasId !== state.canvasId) { const { canvasId } = urlState; const canvas = canvases[canvasId]; diff --git a/src/ui/Renderer3D.js b/src/ui/Renderer3D.js index 894227c..2252bf3 100644 --- a/src/ui/Renderer3D.js +++ b/src/ui/Renderer3D.js @@ -370,6 +370,19 @@ class Renderer3D extends Renderer { this.objects = newObjects; } + debug(ident) { + if (process?.env.NODE_ENV !== 'development') { + return; + } + if (this.lol !== ident) { + // eslint-disable-next-line no-console + console.log(this.lol, this.lola); + this.lol = ident; + this.lola = 0; + } + this.lola += 1; + } + render() { if (!this.threeRenderer) { return; @@ -388,7 +401,6 @@ class Renderer3D extends Renderer { ) { this.centerChunk = centerChunk; this.forceNextRender = true; - console.log('new cc', this.centerChunk); } } @@ -400,39 +412,21 @@ class Renderer3D extends Renderer { this.reloadChunks(); } - if (this.forceNextRender) { - if (this.lol !== 'force') { - console.log(this.lol, this.lola); - this.lol = 'force'; - this.lola = 0; + if (process?.env.NODE_ENV === 'development') { + if (this.forceNextRender) { + this.debug('force'); + } else if (this.forceNextSubrender) { + this.debug('sub'); + } else if (controlUpdate) { + this.debug('upd'); } - this.lola += 1; - } else if (this.forceNextSubrender) { - if (this.lol !== 'sub') { - console.log(this.lol, this.lola); - this.lol = 'sub'; - this.lola = 0; - } - this.lola += 1; - } else if (controlUpdate) { - if (this.lol !== 'update') { - console.log(this.lol, this.lola); - this.lol = 'update'; - this.lola = 0; - } - this.lola += 1; } this.threeRenderer.render(this.scene, this.camera); this.forceNextRender = false; this.forceNextSubrender = false; - } else { - if (this.lol !== 'skip') { - console.log(this.lol, this.lola); - this.lol = 'skip'; - this.lola = 0; - } - this.lola += 1; + } else if (process?.env.NODE_ENV === 'development') { + this.debug('skip'); } }