Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompiler issue on AM2R #798

Closed
Miepee opened this issue Mar 20, 2022 · 1 comment · Fixed by #817
Closed

Decompiler issue on AM2R #798

Miepee opened this issue Mar 20, 2022 · 1 comment · Fixed by #817

Comments

@Miepee
Copy link
Contributor

Miepee commented Mar 20, 2022

UTMT 0.4.0.4 has a slight issue trying to decompile AM2R. gml_Script_spawn_random_septogg in particular.

/* 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:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3124
   at UndertaleModLib.Decompiler.Decompiler.HLDecompile(DecompileContext context, Dictionary`2 blocks, Block entryPoint, Block rootExitPoint) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3466
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3556
   at UndertaleModTool.UndertaleCodeEditor.<>c__DisplayClass31_0.<DecompileCode>b__1() in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModTool\Editors\UndertaleCodeEditor.xaml.cs:line 444
*/

Source code for that script can be found here

@Miepee
Copy link
Contributor Author

Miepee commented Mar 28, 2022

For reference, DogScepter is able to decompile it correctly.

To be more exact about the issue, it happens in this do while loop in Decompiler.cs (starting line 3100)

            do
            {
                changed = false;
                for (int i = 0; i < blockList.Length; i++)
                {
                    if (i == entryBlockId)
                        continue;

                    Block b = blockList[i];

                    IEnumerable<Block> e;
                    if (b.conditionalExit)
                    {
                        reverseUse2[0] = b.nextBlockTrue;
                        reverseUse2[1] = b.nextBlockFalse;
                        e = reverseUse2;
                    }
                    else
                    {
                        reverseUse1[0] = b.nextBlockTrue;
                        e = reverseUse1;
                    }

                    foreach (Block pred in e)
                        changed |= dominators[i].And(dominators[pred._CachedIndex], i);
                }
            } while (changed);

Issue occurs on i==46.
b gets this value assigned:
image
And due to nextBlockTrue and nextBlockFalse both being null, that screws with e, as it gets this assignment then:
image
The foreach goes through e, assigns null to pred, and then crashes while trying to get pred._CachedIndex.

BenjaminUrquhart added a commit to BenjaminUrquhart/UndertaleModTool that referenced this issue Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant