You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running emcc with flag -s MODULARIZE=1 -s environment=web, it will generate a commonJS module.
Inside the module function, it stores the wasmMemory and other staff, and it replaces the original canvas.getContext with getContextSafariWebGL2Fixed
// BUG: Workaround Safari WebGL issue: After successfully acquiring WebGL context on a canvas,
// calling .getContext() will always return that context independent of which 'webgl' or 'webgl2'
// context version was passed. See https://bugs.webkit.org/show_bug.cgi?id=222758 and
// https://github.com/emscripten-core/emscripten/issues/13295.
// TODO: Once the bug is fixed and shipped in Safari, adjust the Safari version field in above check.
if (!canvas.getContextSafariWebGL2Fixed) {
canvas.getContextSafariWebGL2Fixed = canvas.getContext;
/** @type {function(this:HTMLCanvasElement, string, (Object|null)=): (Object|null)} */
function fixedGetContext(ver, attrs) {
var gl = canvas.getContextSafariWebGL2Fixed(ver, attrs);
return ((ver == 'webgl') == (gl instanceof WebGLRenderingContext)) ? gl : null;
}
canvas.getContext = fixedGetContext;
}
Usually this is not a problem, however, I want to "reload" the module, in order to GC the whole wasmMemory buffer.
For example:
delete require.cache[require.resolve('./mywasm.js')];
var module = require('./mywasm.js')
However, I found out that as long as this function is kept by the canvas element, and the canvas element is kept by the DOM tree, or by some JavaScript (e.g. FiberNode on React), the memory will be kept alive indirectly
Possible solution I found:
Remove the canvas from the DOM tree directly, and make sure no reference to the unattached DOM as well (which is not MVVM framework like React and Angular is designed to do ...)
Delete this monkey patch function manually
Or is there a flag so that this function will not be generated because I don't need to support Safari
The text was updated successfully, but these errors were encountered:
If you don't need to support Safari then you can set -sMIN_SAFARI_VERSION=-1.
Separately, as Safari fixed the issue over a year ago, probably it was released in the latest version, so we could use a version check to skip this automatically when possible.
When running emcc with flag
-s MODULARIZE=1 -s environment=web
, it will generate a commonJS module.Inside the module function, it stores the wasmMemory and other staff, and it replaces the original
canvas.getContext
with getContextSafariWebGL2FixedUsually this is not a problem, however, I want to "reload" the module, in order to GC the whole wasmMemory buffer.
For example:
However, I found out that as long as this function is kept by the canvas element, and the canvas element is kept by the DOM tree, or by some JavaScript (e.g. FiberNode on React), the memory will be kept alive indirectly
Possible solution I found:
Or is there a flag so that this function will not be generated because I don't need to support Safari
The text was updated successfully, but these errors were encountered: