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

Aperta
#3,688 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
csharp
Ambito
devtools

Direzione di ricerca

Inizia dalle righe 619–625 collegate di TMP_FontAsset.cs e riproduci la decompilazione C# usando l’IL mostrato nell’issue. Segui il percorso di decompilazione C# di ILSpy per questa condizione e confronta il suo output con la forma if/else prevista da dnSpyEx; il lavoro è completato quando l’output rimane sincronizzato con l’IL e non emette più l’espressione ternaria errata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
C#
Stelle
27.1k
Fork
3.8k
Merge medio
1g 23h
PR unite (30g)
44

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di icsharpcode/ILSpy

Tutte le issue di icsharpcode/ILSpy

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.