Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Toolbar compound brush menu threw OutOfRangeException. #217

Merged
merged 2 commits into from
Feb 1, 2019

Conversation

Henry00IS
Copy link
Collaborator

image
It seems this anonymous lambda method will use the latest value of i which is 2 as the loop ended, not the current value at the time of the iteration.

image
It appears to be a Unity IL bug that causes "i" to be "2" in the lambda expression unless we assign it to a scoped variable.

@vertxxyz
Copy link

vertxxyz commented Jan 14, 2019

It's a C# behaviour in loops, not a Unity IL bug.
For loops and anonymous functions have had this issue and it's pretty widely known about.
C# 5.0 fixed the issue for foreach loops:
https://blogs.msdn.microsoft.com/ericlippert/2009/11/16/closing-over-the-loop-variable-part-two/

If you want to know more you can google: loop closure c#

@Henry00IS Henry00IS merged commit c6bc2b7 into sabresaurus:master Feb 1, 2019
@Henry00IS Henry00IS deleted the ToolbarBrushMenuOutOfRange branch February 1, 2019 16:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants