本文介绍了webglcontextcreationerror事件:是否同步触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同步或异步触发吗?例如

  canvas.addEventListener(webglcontextcreationerror,function(){
console.log(Error );
});
var context = canvas.getContext(webgl);
console.log(创建后);

在错误输出的情况下

创建后
错误



 错误
创建后



我不确定如何强制这个事件自己找出答案。 b 注意:这不是每个规范的答案,而是仅来自单个UA测试,因此可能是错误的,或者至少只适用于这个UA,也就是Chrome。






在chrome中,为了强制错误事件,您可以首先请求一个2dContext然后一个webgl。

通过这种方式,我们可以看到这个UA将事件视为同步事件。



{snippet.log(Error);}); canvas.getContext('2d')canvas.getContext(webgl); snippet.log(创建后);

<! - 提供`snippet`对象,请参阅http://meta.stackexchange.com / a / 242144/134069 - >< script src =http://tjcrowder.github.io/simple-snippets-console/snippet.js>< / script>


Is the webglcontextcreationerror event triggered synchronously or asynchronously? For example does

canvas.addEventListener("webglcontextcreationerror", function() {
  console.log("Error");
});
var context = canvas.getContext("webgl");
console.log("After creation");

in the case of error output

"After creation"
"Error"

or

"Error"
"After creation"

?

I am unsure how to force this event to find out the answer myself.

解决方案

NB : This is not a per spec answer, but only from a single UA test, so it may be wrong, or at least true only to this UA, a.k.a Chrome.


In chrome, to force the error event, you can first request a 2dContext then a webgl one.

This way we can see that this UA does treat the event as an synchronous one.

var canvas = document.createElement('canvas')

canvas.addEventListener("webglcontextcreationerror", function() {
  snippet.log("Error");
});

canvas.getContext('2d')
canvas.getContext("webgl");

snippet.log("After creation");
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>

这篇关于webglcontextcreationerror事件:是否同步触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:14