From 21ffed7cfc6adc6b7beb54a69df7be97e1ad5722 Mon Sep 17 00:00:00 2001 From: Pazaz Date: Sat, 13 Jul 2024 03:24:27 -0400 Subject: [PATCH] fix: Chrome arm drawing bug Wrapped model priorities in empty try-catch to prevent priority == 3 loop getting optimized away Disabling V8 optimizer fixes this too :') Yes it specifically has to go inside the loop, and I added it to all to future proof this --- src/js/jagex2/graphics/Model.ts | 110 ++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 47 deletions(-) diff --git a/src/js/jagex2/graphics/Model.ts b/src/js/jagex2/graphics/Model.ts index b0dd86ab..2cf93fe6 100644 --- a/src/js/jagex2/graphics/Model.ts +++ b/src/js/jagex2/graphics/Model.ts @@ -2342,53 +2342,65 @@ export default class Model extends Hashable { for (let priority: number = 0; priority < 10; priority++) { while (priority === 0 && priorityDepth > averagePriorityDepthSum1_2) { - this.drawFace(priorityFaces[priorityFace++], wireframe); - - if (priorityFace === priorityFaceCount && priorityFaces !== Model.tmpPriorityFaces[11]) { - priorityFace = 0; - priorityFaceCount = Model.tmpPriorityFaceCount[11]; - priorityFaces = Model.tmpPriorityFaces[11]; - priorityFaceDepths = Model.tmpPriority11FaceDepth; - } + try { + this.drawFace(priorityFaces[priorityFace++], wireframe); + + if (priorityFace === priorityFaceCount && priorityFaces !== Model.tmpPriorityFaces[11]) { + priorityFace = 0; + priorityFaceCount = Model.tmpPriorityFaceCount[11]; + priorityFaces = Model.tmpPriorityFaces[11]; + priorityFaceDepths = Model.tmpPriority11FaceDepth; + } - if (priorityFace < priorityFaceCount && priorityFaceDepths) { - priorityDepth = priorityFaceDepths[priorityFace]; - } else { - priorityDepth = -1000; + if (priorityFace < priorityFaceCount && priorityFaceDepths) { + priorityDepth = priorityFaceDepths[priorityFace]; + } else { + priorityDepth = -1000; + } + } catch (e) { + // chrome's V8 optimizer hates us } } while (priority === 3 && priorityDepth > averagePriorityDepthSum3_4) { - this.drawFace(priorityFaces[priorityFace++], wireframe); - - if (priorityFace === priorityFaceCount && priorityFaces !== Model.tmpPriorityFaces[11]) { - priorityFace = 0; - priorityFaceCount = Model.tmpPriorityFaceCount[11]; - priorityFaces = Model.tmpPriorityFaces[11]; - priorityFaceDepths = Model.tmpPriority11FaceDepth; - } + try { + this.drawFace(priorityFaces[priorityFace++], wireframe); + + if (priorityFace === priorityFaceCount && priorityFaces !== Model.tmpPriorityFaces[11]) { + priorityFace = 0; + priorityFaceCount = Model.tmpPriorityFaceCount[11]; + priorityFaces = Model.tmpPriorityFaces[11]; + priorityFaceDepths = Model.tmpPriority11FaceDepth; + } - if (priorityFace < priorityFaceCount && priorityFaceDepths) { - priorityDepth = priorityFaceDepths[priorityFace]; - } else { - priorityDepth = -1000; + if (priorityFace < priorityFaceCount && priorityFaceDepths) { + priorityDepth = priorityFaceDepths[priorityFace]; + } else { + priorityDepth = -1000; + } + } catch (e) { + // chrome's V8 optimizer hates us } } while (priority === 5 && priorityDepth > averagePriorityDepthSum6_8) { - this.drawFace(priorityFaces[priorityFace++], wireframe); - - if (priorityFace === priorityFaceCount && priorityFaces !== Model.tmpPriorityFaces[11]) { - priorityFace = 0; - priorityFaceCount = Model.tmpPriorityFaceCount[11]; - priorityFaces = Model.tmpPriorityFaces[11]; - priorityFaceDepths = Model.tmpPriority11FaceDepth; - } + try { + this.drawFace(priorityFaces[priorityFace++], wireframe); + + if (priorityFace === priorityFaceCount && priorityFaces !== Model.tmpPriorityFaces[11]) { + priorityFace = 0; + priorityFaceCount = Model.tmpPriorityFaceCount[11]; + priorityFaces = Model.tmpPriorityFaces[11]; + priorityFaceDepths = Model.tmpPriority11FaceDepth; + } - if (priorityFace < priorityFaceCount && priorityFaceDepths) { - priorityDepth = priorityFaceDepths[priorityFace]; - } else { - priorityDepth = -1000; + if (priorityFace < priorityFaceCount && priorityFaceDepths) { + priorityDepth = priorityFaceDepths[priorityFace]; + } else { + priorityDepth = -1000; + } + } catch (e) { + // chrome's V8 optimizer hates us } } @@ -2401,19 +2413,23 @@ export default class Model extends Hashable { } while (priorityDepth !== -1000) { - this.drawFace(priorityFaces[priorityFace++], wireframe); + try { + this.drawFace(priorityFaces[priorityFace++], wireframe); - if (priorityFace === priorityFaceCount && priorityFaces !== Model.tmpPriorityFaces[11]) { - priorityFace = 0; - priorityFaces = Model.tmpPriorityFaces[11]; - priorityFaceCount = Model.tmpPriorityFaceCount[11]; - priorityFaceDepths = Model.tmpPriority11FaceDepth; - } + if (priorityFace === priorityFaceCount && priorityFaces !== Model.tmpPriorityFaces[11]) { + priorityFace = 0; + priorityFaces = Model.tmpPriorityFaces[11]; + priorityFaceCount = Model.tmpPriorityFaceCount[11]; + priorityFaceDepths = Model.tmpPriority11FaceDepth; + } - if (priorityFace < priorityFaceCount && priorityFaceDepths) { - priorityDepth = priorityFaceDepths[priorityFace]; - } else { - priorityDepth = -1000; + if (priorityFace < priorityFaceCount && priorityFaceDepths) { + priorityDepth = priorityFaceDepths[priorityFace]; + } else { + priorityDepth = -1000; + } + } catch (e) { + // chrome's V8 optimizer hates us } } }