microsoft / microsoft/TypeScript
WebGL(2) context methods don't allow null for resource parameters
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 Search Terms
WebGL2RenderingContext, attachShader, createShader, null
🕗 Version & Regression Information
- This is the behavior in every version I tried (Nightly, 5.4.5, 4.9.5, 3.9.7), and I reviewed the FAQ for entries about WebGL
⏯ Playground Link
💻 Code
export type ShaderType = WebGL2RenderingContext['FRAGMENT_SHADER'] | WebGL2RenderingContext['VERTEX_SHADER'];
export function loadShader(gl: WebGL2RenderingContext, source: string, type: ShaderType): WebGLShader | null {
const shader = gl.createShader(type);
// if you uncomment those lines it works but goes against the recomendations at https://www.khronos.org/webgl/wiki/HandlingContextLost#Don%E2%80%99t_check_for_null_on_creation
// if (shader === null) {
// throw new Error("shader is null, you've lost context");
// }
gl.shaderSource(shader, source);
gl.compileShader(shader);
const success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
if (success) {
return shader;
}
console.error(gl.getShaderInfoLog(shader));
gl.deleteShader(shader);
return null;
}
🙁 Actual behavior
Context methods that take in WebGL resources (shader, program, buffer...) report errors when provided with null but create* methods return the resource (pointer) or null, and the spec says we should not check for null upon resource creation because all functions accept null as a parameter (no-op).
example :
gl.shaderSource(shader, source);
Argument of type 'WebGLShader | null' is not assignable to parameter of type 'WebGLShader'.
Type 'null' is not assignable to type 'WebGLShader'.
🙂 Expected behavior
Context methods taking resources as parameters should allow for null to be passed in. This would delineate from MDN's documentation but fit closer to the actual behavior of the API and the WebGL(2) spec.
Additional information about the issue
No response
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con las declaraciones de WebGL2RenderingContext utilizadas por el playground de TypeScript enlazado y revisa métodos que reciben recursos, como shaderSource, compileShader y getShaderParameter. Compara sus tipos de parámetros con los resultados anulables de createShader y con las indicaciones enlazadas sobre la pérdida del contexto WebGL. Se considera completado cuando los parámetros de recursos WebGL relevantes aceptan null y el playground deja de mostrar el diagnóstico indicado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- web-dev
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100