C# decompilation uses ternary conditional operator instead of if else, and causes desync on IL with C#.

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

メンテナーはふだん 1 日以内に返信

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
csharp
領域
devtools

調査の方向性

リンクされている TMP_FontAsset.cs の 619–625 行から始め、issue に示されている IL を使って C# のデコンパイル結果を再現します。この条件分岐に対する ILSpy の C# デコンパイルパスを追跡し、その出力を dnSpyEx による期待される if/else 形式と比較します。完了とは、出力が IL と同期したままになり、誤った三項式を出力しなくなることです。

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

説明

Bug Decompiler
Input code

https://github.com/Lightning-Forge-Games/uGUI/blob/8686abb727366154be46c3062c24cfe5183d3d4e/com.unity.ugui/Runtime/TMP/TMP_FontAsset.cs#L619-L625

if (texFormat == TextureFormat.Alpha8)
    tmp_material = new Material(ShaderUtilities.ShaderRef_MobileBitmap);
else
    tmp_material = new Material(Shader.Find("TextMeshPro/Sprite"));

//tmp_material.name = texture.name + " Material";
tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture);
Erroneous output

Instead of doing if else, it decompiles as ternarny conditional, and desyncs the IL when using mixed.

	// material = ((textureFormat != TextureFormat.Alpha8) ? new Material(Shader.Find("TextMeshPro/Sprite")) : new Material(ShaderUtilities.ShaderRef_MobileBitmap));
	IL_00a8: ldloc.1
	IL_00a9: ldc.i4.1
	IL_00aa: bne.un.s IL_00ba

	IL_00ac: call class [UnityEngine.CoreModule]UnityEngine.Shader TMPro.ShaderUtilities::get_ShaderRef_MobileBitmap()
	IL_00b1: newobj instance void [UnityEngine.CoreModule]UnityEngine.Material::.ctor(class [UnityEngine.CoreModule]UnityEngine.Shader)
	IL_00b6: stloc.s 4
	// (no C# code)
	IL_00b8: br.s IL_00cb

	// material.SetTexture(ShaderUtilities.ID_MainTex, texture2D);
	IL_00ba: ldstr "TextMeshPro/Sprite"
	IL_00bf: call class [UnityEngine.CoreModule]UnityEngine.Shader [UnityEngine.CoreModule]UnityEngine.Shader::Find(string)
	IL_00c4: newobj instance void [UnityEngine.CoreModule]UnityEngine.Material::.ctor(class [UnityEngine.CoreModule]UnityEngine.Shader)
	IL_00c9: stloc.s 4

	IL_00cb: ldloc.s 4
	IL_00cd: ldsfld int32 TMPro.ShaderUtilities::ID_MainTex
	IL_00d2: ldloc.2
	IL_00d3: callvirt instance void [UnityEngine.CoreModule]UnityEngine.Material::SetTexture(int32, class [UnityEngine.CoreModule]UnityEngine.Texture)
Expected decompilation

Example is from using DnSpyEx v6.5.1
Image

Details
  • Product in use: ILSpy 10.0 Preview 2
  • Version in use: Latest one, but same problem is also on older versions.
  • The correct behaviour happens on DnSpyEx.
主要言語
C#
スター
27.1k
フォーク
3.8k
平均マージ
1日 23時間
マージ済み PR(30日)
44

環境構築

はじめの一歩

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

icsharpcode/ILSpy のほかの issue

icsharpcode/ILSpy の issue をすべて見る

似ている issue

C# の issue をもっと見る

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

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