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

Temporary local variable dropped after popenv? #12

Closed
Siuhnexus opened this issue Mar 9, 2025 · 2 comments
Closed

Temporary local variable dropped after popenv? #12

Siuhnexus opened this issue Mar 9, 2025 · 2 comments
Labels
bug Something isn't working decompiler Involves the decompiler

Comments

@Siuhnexus
Copy link

Incorrect output observed

The following bytecode threw an error, and since I didn't find anything in the Issues for the compiler I suspect something went wrong while decompiling:

> gml_Script_TwFindById (locals=0, argc=1)
:[1551]
pushref.i 100
pushi.e -9
pushenv [1554]

:[1552]
push.v builtin.N
push.v arg.argument0
cmp.v.v EQ
bf [1554]

:[1553]
push.v builtin.id
pop.v.v local.$$$$temp$$$$
popenv <drop>
push.v local.$$$$temp$$$$
ret.v

The error thrown:

Variable <unknown_object>.$$$$temp$$$$(100080, -2147483648) not set before reading it.
at gml_Script_TwFindById

Could it be that local.$$$$temp$$$$ is dropped after popenv and that's why it's not set in the outer context?

Expected output

I have no clue

VM assembly

Additional context
The decompiled code is this:

function TwFindById(argument0)
{
    with (tower)
    {
        if (N == argument0)
            return id;
    }
    
    return -1;
}
@Siuhnexus Siuhnexus added bug Something isn't working decompiler Involves the decompiler labels Mar 9, 2025
@colinator27
Copy link
Member

This seems pretty peculiar... The decompilation looks correct, so it's possible that this is a compiler bug, but there's not quite enough information to figure out what went wrong. (It may even be a different part of the code?)

Did you use UndertaleModTool to re-compile the code? If so, what version? I just opened a PR for the new Underanalyzer compiler here, but I'm not sure if you're using that version or not: UnderminersTeam/UndertaleModTool#2056.

@Siuhnexus
Copy link
Author

I am sorry, I tested this with the underanalyzer branch and not with the underanalyzer-compiler branch. Switching solved all my problems. Thank you so much for your awesome work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working decompiler Involves the decompiler
Projects
None yet
Development

No branches or pull requests

2 participants