Skip to content

Commit b699345

Browse files
committedNov 17, 2024·
build
1 parent a8ea6ed commit b699345

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed
 

‎webgl-memory.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* webgl-memory@1.0.16, license MIT */
1+
/* webgl-memory@1.1.1, license MIT */
22
(function (factory) {
33
typeof define === 'function' && define.amd ? define(factory) :
44
factory();
@@ -396,6 +396,22 @@
396396
return typeof v === 'number';
397397
}
398398

399+
function collectObjects(state, type) {
400+
const list = [...state.webglObjectToMemory.keys()]
401+
.filter(obj => obj instanceof type)
402+
.map((obj) => state.webglObjectToMemory.get(obj));
403+
404+
return list;
405+
}
406+
407+
function getStackTrace() {
408+
const stack = (new Error()).stack;
409+
const lines = stack.split('\n');
410+
// Remove the first two entries, the error message and this function itself, or the webgl-memory itself.
411+
const userLines = lines.slice(2).filter((l) => !l.includes('webgl-memory.js'));
412+
return userLines.join('\n');
413+
}
414+
399415
/*
400416
The MIT License (MIT)
401417
@@ -419,7 +435,6 @@
419435
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
420436
*/
421437

422-
423438
//------------ [ from https://github.com/KhronosGroup/WebGLDeveloperTools ]
424439

425440
/*
@@ -487,6 +502,9 @@
487502
},
488503
};
489504
},
505+
getResourcesInfo(type) {
506+
return collectObjects(sharedState, type);
507+
},
490508
},
491509
},
492510
},
@@ -592,6 +610,7 @@
592610
++resources[typeName];
593611
webglObjectToMemory.set(webglObj, {
594612
size: 0,
613+
stackCreated: getStackTrace(),
595614
});
596615
};
597616
}
@@ -634,6 +653,7 @@
634653

635654
memory.renderbuffer -= info.size;
636655
info.size = newSize;
656+
info.stackUpdated = getStackTrace();
637657
memory.renderbuffer += newSize;
638658
}
639659

@@ -703,6 +723,8 @@
703723

704724
memory.texture -= oldSize;
705725
memory.texture += info.size;
726+
727+
info.stackUpdated = getStackTrace();
706728
}
707729

708730
function updateTexStorage(target, levels, internalFormat, width, height, depth) {
@@ -789,6 +811,7 @@
789811

790812
memory.buffer -= info.size;
791813
info.size = newSize;
814+
info.stackUpdated = getStackTrace();
792815
memory.buffer += newSize;
793816
},
794817

@@ -1121,7 +1144,6 @@
11211144
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11221145
*/
11231146

1124-
11251147
function wrapGetContext(Ctor) {
11261148
const oldFn = Ctor.prototype.getContext;
11271149
Ctor.prototype.getContext = function(type, ...args) {

0 commit comments

Comments
 (0)
Please sign in to comment.