diff --git a/webgl-memory.js b/webgl-memory.js index e4637d9..ad98dac 100644 --- a/webgl-memory.js +++ b/webgl-memory.js @@ -1,4 +1,4 @@ -/* webgl-memory@1.0.16, license MIT */ +/* webgl-memory@1.1.1, license MIT */ (function (factory) { typeof define === 'function' && define.amd ? define(factory) : factory(); @@ -396,6 +396,22 @@ return typeof v === 'number'; } + function collectObjects(state, type) { + const list = [...state.webglObjectToMemory.keys()] + .filter(obj => obj instanceof type) + .map((obj) => state.webglObjectToMemory.get(obj)); + + return list; + } + + function getStackTrace() { + const stack = (new Error()).stack; + const lines = stack.split('\n'); + // Remove the first two entries, the error message and this function itself, or the webgl-memory itself. + const userLines = lines.slice(2).filter((l) => !l.includes('webgl-memory.js')); + return userLines.join('\n'); + } + /* The MIT License (MIT) @@ -419,7 +435,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - //------------ [ from https://github.com/KhronosGroup/WebGLDeveloperTools ] /* @@ -487,6 +502,9 @@ }, }; }, + getResourcesInfo(type) { + return collectObjects(sharedState, type); + }, }, }, }, @@ -592,6 +610,7 @@ ++resources[typeName]; webglObjectToMemory.set(webglObj, { size: 0, + stackCreated: getStackTrace(), }); }; } @@ -634,6 +653,7 @@ memory.renderbuffer -= info.size; info.size = newSize; + info.stackUpdated = getStackTrace(); memory.renderbuffer += newSize; } @@ -703,6 +723,8 @@ memory.texture -= oldSize; memory.texture += info.size; + + info.stackUpdated = getStackTrace(); } function updateTexStorage(target, levels, internalFormat, width, height, depth) { @@ -789,6 +811,7 @@ memory.buffer -= info.size; info.size = newSize; + info.stackUpdated = getStackTrace(); memory.buffer += newSize; }, @@ -1121,7 +1144,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - function wrapGetContext(Ctor) { const oldFn = Ctor.prototype.getContext; Ctor.prototype.getContext = function(type, ...args) {