/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/rendering/renderers/gl/shader/program/logProgramError.ts
101 строка
3 KB
Zyie
fix: handle null from getShaderSource/getShaderInfoLog on lost context (#12032) (#12042)
01 июн 2026, 11:10
Не верифицирован
01 июн 2026, 11:10
a1c4e98
Код
Авторство
О чём код?
/** * will log a shader error highlighting the lines with the error * also will add numbers along the side. * @param gl - the WebGLContext * @param shader - the shader to log errors for */ function logPrettyShaderError(gl: WebGLRenderingContext, shader: WebGLShader): void { // getShaderSource returns null on GL errors (e.g. lost context); see // https://registry.khronos.org/webgl/specs/latest/1.0/#5.14.9 const rawSource = gl.getShaderSource(shader); if (rawSource === null) { console.error('PixiJS Error: Could not retrieve shader source (WebGL context may be lost).'); return; } const shaderSrc = rawSource .split('\n') .map((line, index) => `${index}: ${line}`); const shaderLog = gl.getShaderInfoLog(shader) ?? ''; const splitShader = shaderLog.split('\n'); const dedupe: Record<number, boolean> = {}; const lineNumbers = splitShader.map((line) => parseFloat(line.replace(/^ERROR\: 0\:([\d]+)\:.*$/, '$1'))) .filter((n) => { if (n && !dedupe[n]) { dedupe[n] = true; return true; } return false; }); const logArgs = ['']; lineNumbers.forEach((number) => { shaderSrc[number - 1] = `%c${shaderSrc[number - 1]}%c`; logArgs.push('background: #FF0000; color:#FFFFFF; font-size: 10px', 'font-size: 10px'); }); const fragmentSourceToLog = shaderSrc .join('\n'); logArgs[0] = fragmentSourceToLog; console.error(shaderLog); // eslint-disable-next-line no-console console.groupCollapsed('click to view full shader code'); console.warn(...logArgs); // eslint-disable-next-line no-console console.groupEnd(); } /** * * logs out any program errors * @param gl - The current WebGL context * @param program - the WebGL program to display errors for * @param vertexShader - the fragment WebGL shader program * @param fragmentShader - the vertex WebGL shader program * @private */ export function logProgramError( gl: WebGLRenderingContext, program: WebGLProgram, vertexShader: WebGLShader, fragmentShader: WebGLShader ): void { // if linking fails, then log and cleanup if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) { logPrettyShaderError(gl, vertexShader); } if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) { logPrettyShaderError(gl, fragmentShader); } console.error('PixiJS Error: Could not initialize shader.'); // if there is a program info log, log it if (gl.getProgramInfoLog(program) !== '') { console.warn('PixiJS Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program)); } } }