UndertaleModTool icon indicating copy to clipboard operation
UndertaleModTool copied to clipboard

NullReferenceException when decompiling a do-until loop

Open mwiatrowski opened this issue 3 years ago • 1 comments

I compiled the following script:

var value = 0;
do {
    value = irandom(100);
} until (value < 50);

This is the resulting assembly:

.localvar 0 arguments
.localvar 1 value 1

:[0]
pushi.e 0
pop.v.i local.value

:[1]
pushi.e 100
conv.i.v
call.i irandom(argc=1)
pop.v.v local.value
pushloc.v local.value
pushi.e 50
cmp.i.v LT
bf [1]

:[end]

After that, I tried to decompile it back into a script, but got an error:

/* EXCEPTION!
   System.NullReferenceException: Object reference not set to an instance of an object.
   at UndertaleModLib.Decompiler.Decompiler.ComputeReverseDominators(Dictionary`2 blocks, Block entryBlock) in D:\kod\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2978
   at UndertaleModLib.Decompiler.Decompiler.HLDecompile(DecompileContext context, Dictionary`2 blocks, Block entryPoint, Block rootExitPoint) in D:\kod\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3318
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\kod\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3432
   at UndertaleModTool.UndertaleCodeEditor.<>c__DisplayClass26_1.<DecompileCode>b__1() in D:\kod\UndertaleModTool\UndertaleModTool\Editors\UndertaleCodeEditor.xaml.cs:line 344
*/

I suspect there's a problem with flow graph generation. Here's a screenshot from debugger: obraz

mwiatrowski avatar Oct 28 '21 16:10 mwiatrowski

Current bleeding edge doesn't seem to have a complete decompilation crash, but still yields the disappearance described in #268.

Jacky720 avatar Feb 21 '24 18:02 Jacky720