From efb28d16a2c3c61819a8b7e56d1a5f21eebb27e2 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 25 May 2023 20:19:46 +0200 Subject: [PATCH] gpstrek - Fix out of memory with long routes (hundreds of waypoints) --- apps/gpstrek/app.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/gpstrek/app.js b/apps/gpstrek/app.js index 22d3c4f48..811b9bf92 100644 --- a/apps/gpstrek/app.js +++ b/apps/gpstrek/app.js @@ -220,12 +220,12 @@ let timeoutQueue = []; let queueProcessing = false; let addToTimeoutQueue = function (func, data){ - if (queueProcessing) return; + if (queueProcessing) print("Adding during processing, this should not happen"); timeoutQueue.push({f:func,d:data}); }; -let prependTimeoutQueue = function (func, data){ - if (queueProcessing) return; +let prependTimeoutQueue = function (func, data, force){ + if (queueProcessing && !force) print("Prepending during processing, this should not happen"); timeoutQueue.unshift({f:func,d:data}); }; @@ -473,14 +473,17 @@ let getMapSlice = function(){ toDraw = null; } + if (!isMapOverview && Math.abs(data.i) > SETTINGS.maxPoints) + data.breakLoop = true; + if (!data.breakLoop){ + //be careful when modifying the queue during processing + prependTimeoutQueue(drawChunk, data, true); + } }; - let startIndex = 0; - do { - addToTimeoutQueue(drawChunk, data); - startIndex += SETTINGS.mapChunkSize; - } while ((startIndex < SETTINGS.maxPoints || (isMapOverview && startIndex < route.count))); + addToTimeoutQueue(drawChunk, data); }; + drawPath(getNext,false); drawPath(getPrev,true);