facebook twitter hatena line email

「Unity/負荷軽減/WebGL」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(OutOfMemoryを引き起こす)
(OutOfMemoryのエラーを受け取る)
行1: 行1:
  
==OutOfMemoryのエラーを受け取る==
+
==範囲外のメモリアクセスのエラーを受け取る==
 
<pre>
 
<pre>
 
UnityLoader.Error.handler = function(e, t)
 
UnityLoader.Error.handler = function(e, t)

2021年6月3日 (木) 17:26時点における版

範囲外のメモリアクセスのエラーを受け取る

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"のエラーを受け取れる

OutOfMemoryを引き起こす

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

参考

メモリをPlayer設定で変えられる? https://gist.github.com/yukpiz/ba32278995f160d6cb99d30e1eff804a

Loader.jsのソース? https://gist.github.com/kyptov/f7e4718ee93b5c42bb975bc006fb10b4

Unity Playerの設定(TOTAL_MEMORYプロパティ)を外部から書き換えれば起こりづらくなる。

http://blog.livedoor.jp/hofupifoba/archives/17053937.html https://qiita.com/kingyo222/items/1995383a394251abd86d

TOTAL_MEMORY」というプロパティがあるので数値を直接修正 https://jpn.itlibra.com/article?id=10941

メモリ変更:Player Settings -> Publishing Setting -> Memory Size https://www.hanachiru-blog.com/entry/2019/10/04/000000

developmentBuildをonにすると、UnityLoader.Error.handler = (e) => console.log(e);でいかがキャッチできる。 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. Module: { TOTAL_STACK: 8.9 * 1024 }のようにすると以下メッセージが出る。 Uncaught RuntimeError: memory access out of bounds