Skip to content

Commit

Permalink
fix: correct buffer length calculation error
Browse files Browse the repository at this point in the history
  • Loading branch information
06wj committed Jan 11, 2025
1 parent 182e23d commit 7e74633
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@shaderfrog/glsl-parser": "^2.0.1"
"@shaderfrog/glsl-parser": "^5.0.0"
},
"devDependencies": {
"@types/webxr": "^0.5.1",
Expand Down
44 changes: 24 additions & 20 deletions src/backend/recorders/bufferRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,29 @@ export class BufferRecorder extends BaseRecorder<WebGLBuffer> {

protected getLength(functionInformation: IFunctionInformation): number {
/* tslint:disable */
let length = -1;
let offset = 0;
if (functionInformation.arguments.length === 5) {
length = functionInformation.arguments[4];
offset = functionInformation.arguments[3];
}

if (length <= 0) {
if (typeof functionInformation.arguments[1] === "number") {
length = functionInformation.arguments[1];
}
else if (functionInformation.arguments[1]) {
length = functionInformation.arguments[1].byteLength || functionInformation.arguments[1].length || 0;
}
else {
length = 0;
}
}

return length - offset;
const sizeOrData = functionInformation.arguments[1];
const offset = functionInformation.arguments[3];
const length = functionInformation.arguments[4];

// bufferData(target, size, usage)
if (typeof sizeOrData === 'number') {
return sizeOrData;
}

// bufferData(target, srcData, usage, srcOffset, length)
if (typeof length === 'number' && length > 0) {
return length;
}

const dataLength = sizeOrData.byteLength || sizeOrData.length || 0;

// bufferData(target, srcData, usage, srcOffset)
if (typeof offset === 'number' && offset > 0) {
return dataLength - offset;
}
// bufferData(target, srcData, usage)
else {
return dataLength;
}
}
}

0 comments on commit 7e74633

Please sign in to comment.