microsoft / microsoft/TypeScript
WebGL(2) context methods don't allow null for resource parameters
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Parti dalle dichiarazioni di WebGL2RenderingContext utilizzate dal playground TypeScript collegato ed esamina i metodi che ricevono risorse, come shaderSource, compileShader e getShaderParameter. Confronta i relativi tipi dei parametri con i risultati nullable di createShader e con le indicazioni collegate sulla perdita del contesto WebGL. Il lavoro è completato quando i parametri delle risorse WebGL pertinenti accettano null e il playground non segnala più la diagnostica mostrata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- web-dev
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100