如何检测渲染过程中 three.js 何时引发错误?



当用three.js做一些事情时,我注意到一些限制,这取决于代码在哪个客户端上运行。一个例子是,如果我有很多MeshPhongMaterialLight,并在低端笔记本电脑/手机上尝试,我会收到着色器错误。有时requestAnimationFrame()会完全停止执行,有时我只会得到这个错误(和 WebGL 警告(的墙壁和墙壁。

我的问题是是否有可能捕获这些错误?使用try-catch做了一个小的压力测试脚本,但即使在错误和警告之后也永远不会调用catch

var rendering = function()
{
lights.push(new THREE.PointLight());
lights[lights.length-1].position.set((Math.random()*10)-5,(Math.random()*10)-5,(Math.random()*10)-5);
scene.add(lights[lights.length-1]);
try
{
renderer.render(scene,camera);
}
catch(e)
{
console.log("Limit!"); // never shown
}
requestAnimationFrame(rendering);
}

console.error = yourFunction(( console.warning = yourFunction((

检查其中的消息,并对它们执行一些操作。

最新更新