Code: Select all
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const glContextAttributes = { alpha: true, antialias: false };
let gl = canvas.getContext('webgl2', glContextAttributes);
if (!gl) {
console.log('WebGL2 not supported, falling back to WebGL1.');
gl = canvas.getContext('webgl', glContextAttributes);
}
if (!gl) {
throw new Error('WebGL not supported in this browser.');
}
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
document.body.appendChild(canvas);
const shader = gl.createShader(gl.VERTEX_SHADER);
if (!shader) {
debugInfo.glError = gl.getError();
debugInfo.contextLost = gl.isContextLost();
throw new Error(`Failed to create ${gl.VERTEX_SHADER} shader. ${JSON.stringify(debugInfo)}`);
}
Fehler beim Erstellen des 35633-Shaders. {"glError":37442,"contextLost":true
Für die Benutzer, denen das passiert, passiert es in 100 % der Fälle. Ich habe keine Ahnung, wie ich ihnen helfen kann.
Wie konnte der WebGL-Kontext so verloren gehen? Ich habe gerade die Leinwand erstellt. Es ist noch nicht einmal eine einzige Runde der Ereignisschleife vergangen. Kann ich irgendetwas tun, um dies zu verhindern (oder es zumindest abzumildern)?
Mobile version