microsoft / microsoft/TypeScript

WebGL(2) context methods don't allow null for resource parameters

オープン
#58,200 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 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

https://www.typescriptlang.org/play?target=99&jsx=0&ts=5.5.0-dev.20240415#code/KYDwDg9gTgLgBDAnmYcDKALAhgE2FAFWVQF44B1YAIwHEAZAJgCVgA7PKAS1YHMBhCKxigYAbQDkAMSYBBGgFkAogDkCAfTQAJGQBFFTcQF04AHwrV6zNh279BwkGPEA1fQUUANDdr0HDAbgAoQNBIWDgAMwBXVgBjGE5BOAAbCFxMXHwACh5kgC5zWkYWdnxbASERABo4AGcIKKhY4ALamC5eGqQUAoyOIhQASgLKIr78UzhWKOTkuABvQIBIWME2uuwOODJcgDpYqGAsYXGoLO7gQaDlgHobuE4IuEQGuBjVgFsPtngYDAhaqhktxgLUHvAAO7QADWYKoUXgPAgoLgWB4WG46z+qEOn2sx0SrDBxzgGBgMDAtTydwhtN20IwUEEAN20B4Nwh1FyHM40M4N00WHYwN4FQcMDoAJgAGIdIIAKSKBjygAcAAZ5QBOTUwNSxDDAWLQtQRaBqaazNSCPWHAmCYJLO4PJ5ZWqbCYkT1TGbJQYLW73JZ-JkQqbAUOKKBMs4AIjdmSgDzBFuSNReUXEADcgVK4KtKo4Y1cA3AAL7LPbxjhoBpNYCu91QGr1RrNYtLPafMCcZLAU4NhPF5b59a1KKxZq1ME7ZK7HjAGCnAAKWCgWG+wjOVfwNT2fAA8vIlwBJOiKDQEGQEACqaHbjzgrvHk9qfsWSyWhxgjVYGwTQSWcthzWCBe12fBoxyWd50XRtj1YU1JR4AcOEGds9jwXsTkbFD8HbL8f29WYglLIA

💻 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた TypeScript playground で使用されている WebGL2RenderingContext の宣言から始め、shaderSource、compileShader、getShaderParameter などのリソースを受け取るメソッドを確認します。それらのパラメーター型を createShader の nullable な結果およびリンクされた WebGL コンテキスト喪失のガイダンスと比較します。関連する WebGL リソースパラメーターが null を受け入れ、playground に表示された診断が表示されなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
web-dev
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。