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

local variable create oustide a switch scope will be lost on exit if foreach is use in the switch #5366

Closed
DorpsGek opened this issue Nov 15, 2012 · 5 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)

Comments

@DorpsGek
Copy link
Member

krinn opened the ticket and wrote:

I have just hit this too, but glx found a thread where morloth has been affect by it too
http://www.tt-forums.net/viewtopic.php?f=65&t=49176
Looks like last local variable is lost if inside a switch that have a foreach in it

local anything = 0;
local something = null;
// local z = 0; // morloth fix
switch (anything)
{
case 0:
something=AIList();
something.AddItem(0,0);
foreach (item, value in something) { } // comment out this line and it will works too
break;
}
print(something.Count()); <--- this will trigger error "something does not exist"

affect squirrel 2.2.5, i have post it as a reminder for other devs to find the fix (i have seek in flyspray but morloth didn't report it here it seems, glad glx put his fingers on the thread, i was getting mad at it.
I put severity to very low as i just don't think it could be fix easy, the workaround is at least easy.

Reported version: other
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/5366
@DorpsGek
Copy link
Member Author

Yexo wrote:

I've added the code in the description to the Start() function of an otherwise empty test AI, but it didn't crash. Can you provide a complete example that triggers the error?


This comment was imported from FlySpray: https://bugs.openttd.org/task/5366#comment11690

@DorpsGek
Copy link
Member Author

krinn wrote:

This is the sample i've use when speaking about it with glx : http://pastebin.com/xgJLkMn2
But the sample from morloth in the forum thread is another one that fail.

I'm sorry my test case fail, seems my assumption on how it happen is false then.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5366#comment11694

@DorpsGek
Copy link
Member Author

DorpsGek commented Feb 6, 2013

Rubidium wrote:

Without a way to easily reproduce this, it will be very hard to fix it. I tried several incarnations, but most "examples" were missing so much related code that I had to remove that it did not reproduce the issue. So please provide a simple AI that will reliably show this error (without building networks and such).


This comment was imported from FlySpray: https://bugs.openttd.org/task/5366#comment11981

@DorpsGek
Copy link
Member Author

Rubidium closed the ticket.

Reason for closing: Unreproducible

When a reliable way to reproduce this has been created, it may be reopened.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5366

@DorpsGek
Copy link
Member Author

krinn wrote:

No i cannot build an AI where i'm able to reproduce it, from my AI where the bug is still in it i could, so here's my AI modified to enable and trigger the bug per default.
Start the AI, hit fastforward i have add a AIController.Break to help you.

Here's the clues i have to trigger it (but i lack to build an test AI that reproduce the conditions, so something more is need) :
- Have a variable create before a switch case
- Have this variable value (or type?) modified within the switch case
- The case that alter the variable MUST have a foreach loop (!)

Try accessing it then outside the switch will trigger the error the variable doesn't exists.

And the easy way to get mad : uncomment line 220 (the one "local nothing = 0;" and see the bug vanish by magic...

Attachments


This comment was imported from FlySpray: https://bugs.openttd.org/task/5366#comment12768

@DorpsGek DorpsGek added flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) Squirrel labels Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)
Projects
None yet
Development

No branches or pull requests

1 participant