Skip to content

Commit 977845c

Browse files
authored
Merge pull request #315 from 06wj/fix/buffer-length
fix: correct error in buffer length calculation
2 parents 182e23d + 7e74633 commit 977845c

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"test": "echo \"Error: no test specified\" && exit 1"
3535
},
3636
"dependencies": {
37-
"@shaderfrog/glsl-parser": "^2.0.1"
37+
"@shaderfrog/glsl-parser": "^5.0.0"
3838
},
3939
"devDependencies": {
4040
"@types/webxr": "^0.5.1",

src/backend/recorders/bufferRecorder.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,29 @@ export class BufferRecorder extends BaseRecorder<WebGLBuffer> {
101101

102102
protected getLength(functionInformation: IFunctionInformation): number {
103103
/* tslint:disable */
104-
let length = -1;
105-
let offset = 0;
106-
if (functionInformation.arguments.length === 5) {
107-
length = functionInformation.arguments[4];
108-
offset = functionInformation.arguments[3];
109-
}
110-
111-
if (length <= 0) {
112-
if (typeof functionInformation.arguments[1] === "number") {
113-
length = functionInformation.arguments[1];
114-
}
115-
else if (functionInformation.arguments[1]) {
116-
length = functionInformation.arguments[1].byteLength || functionInformation.arguments[1].length || 0;
117-
}
118-
else {
119-
length = 0;
120-
}
121-
}
122-
123-
return length - offset;
104+
const sizeOrData = functionInformation.arguments[1];
105+
const offset = functionInformation.arguments[3];
106+
const length = functionInformation.arguments[4];
107+
108+
// bufferData(target, size, usage)
109+
if (typeof sizeOrData === 'number') {
110+
return sizeOrData;
111+
}
112+
113+
// bufferData(target, srcData, usage, srcOffset, length)
114+
if (typeof length === 'number' && length > 0) {
115+
return length;
116+
}
117+
118+
const dataLength = sizeOrData.byteLength || sizeOrData.length || 0;
119+
120+
// bufferData(target, srcData, usage, srcOffset)
121+
if (typeof offset === 'number' && offset > 0) {
122+
return dataLength - offset;
123+
}
124+
// bufferData(target, srcData, usage)
125+
else {
126+
return dataLength;
127+
}
124128
}
125129
}

0 commit comments

Comments
 (0)