「Unity/負荷軽減/WebGL」の版間の差分
(→OutOfMemoryのログ) |
(→TOTAL_MEMORYの変更方法) |
||
| 行54: | 行54: | ||
} | } | ||
}); | }); | ||
| + | </pre> | ||
| + | 以下エラーメッセージが出る | ||
| + | <pre> | ||
| + | UnityLoader.js:4 failed to asynchronously prepare wasm: LinkError: WebAssembly.instantiate(): memory import 0 is smaller than initial 512, got 496 | ||
| + | UnityLoader.js:4 LinkError: WebAssembly.instantiate(): memory import 0 is smaller than initial 512, got 496 | ||
| + | Uncaught (in promise) abort({}) at Error | ||
</pre> | </pre> | ||
2021年6月3日 (木) 18:28時点における版
範囲外のメモリアクセスのエラーを受け取る
UnityLoader.Error.handler = function(e, t)
{
if (e.message.indexOf("memory access out of bounds") != -1)
{
console.log("message=" + e.message);
}
};
"Uncaught RuntimeError: memory access out of bounds"のエラーを受け取れる
範囲外のメモリアクセスを引き起こす
Unity2019の場合
var unityInstance = UnityLoader.instantiate("unityContainer", "Build/webgl_project.json", {
onProgress: UnityProgress,
Module: { TOTAL_STACK: 9 * 1024 }
});
setInterval(function() {
var text = "";
for (var i = 0; i < 1 * 1024 * 1024; i++) {
text += "a";
}
unityInstance.SendMessage('MyGameObject', 'MyFunction', text);
}, 10000);
参考:https://qiita.com/kingyo222/items/1995383a394251abd86d
他調査
throw new OutOfMemoryException();を実行すると以下エラーが起こる。他のでも起こるかも?だが・・
Uncaught undefined - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch.
OutOfMemoryのログ
Out of memory. は、それはそれでエラーメッセージがある?
Out of memory. If you are the developer of this content, try allocating more memory to your WebGL build in the WebGL player settings.
参考:https://jpn.itlibra.com/article?id=10941
参考:https://nichijou-graffiti.com/dmm-browser-game-out-of-memory-message/
TOTAL_MEMORYの変更方法
var unityInstance = UnityLoader.instantiate("unityContainer", "Build/webgl_project.json", {
onProgress: UnityProgress,
Module: {
TOTAL_STACK: 10 * 1024,
TOTAL_MEMORY:31 * 1024 * 1024
}
});
以下エラーメッセージが出る
UnityLoader.js:4 failed to asynchronously prepare wasm: LinkError: WebAssembly.instantiate(): memory import 0 is smaller than initial 512, got 496
UnityLoader.js:4 LinkError: WebAssembly.instantiate(): memory import 0 is smaller than initial 512, got 496
Uncaught (in promise) abort({}) at Error
参考
メモリ変更:Player Settings/Publishing Setting/Memory Size(2018,2019では欄がない?) https://www.hanachiru-blog.com/entry/2019/10/04/000000
Loader.jsのソース https://gist.github.com/kyptov/f7e4718ee93b5c42bb975bc006fb10b4
Unity Playerの設定(TOTAL_MEMORYプロパティ)を外部から書き換えれば起こりづらくなる。 http://blog.livedoor.jp/hofupifoba/archives/17053937.html
htmlのBuildのjson内に、TOTAL_MEMORYというプロパティがあるので数値を直接修正できる。 https://jpn.itlibra.com/article?id=10941
