Skip to content

Commit

Permalink
fix: Chrome arm drawing bug
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Pazaz committed Jul 13, 2024
1 parent 27a3f3f commit 21ffed7
Showing 1 changed file with 63 additions and 47 deletions.
110 changes: 63 additions & 47 deletions src/js/jagex2/graphics/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 21ffed7

Please sign in to comment.