eric-king / BingoEngine

Fun with C# and BINGO
MIT License
2 stars 1 forks source link

Index out of range exception on console startup #1

Open jennablackwell opened 1 year ago

jennablackwell commented 1 year ago

Thank you for sharing this project! Just a heads up when I try to run the console app in it, I do receive an index out of range exception..

image
eric-king commented 1 year ago

Does this happen with every pattern you choose, or a specific pattern? Did you alter any of the pattern classes?

jennablackwell commented 1 year ago

Hi Eric, I didn't modify anything - just tried to run the console app after downloading the project. Were any arguments supposed to be provided when running?

On Wed, Mar 15, 2023 at 1:26 PM Eric King @.***> wrote:

Does this happen with every pattern you choose, or a specific pattern? Did you alter any of the pattern classes?

— Reply to this email directly, view it on GitHub https://github.com/eric-king/BingoEngine/issues/1#issuecomment-1470547544, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRQHVGGVTHRNIGK76HNUBTW4ICUTANCNFSM6AAAAAAV35MH64 . You are receiving this because you authored the thread.Message ID: @.***>

eric-king commented 1 year ago

No, it should run out of the box. Based on where the error is happening, I'm guessing that maybe the pictogram.Split(Environment.NewLine) is the issue. Perhaps the roundtrip from Windows -> GitHub -> Windows is messing up the encoding or something. I haven't been able to recreate the issue yet, so I'll probably try to clone everything fresh and see if that helps.

eric-king commented 1 year ago

Hmm... I did a fresh clone, built it, and ran it with no problems. I'm running it in VS2022 on Windows. Is your environment different?

jennablackwell commented 1 year ago

Weird - yes VS 2022 on Windows 11.

On Wed, Mar 15, 2023 at 3:16 PM Eric King @.***> wrote:

Hmm... I did a fresh clone, built it, and ran it with no problems. I'm running it in VS2022 on Windows. Is your environment different?

— Reply to this email directly, view it on GitHub https://github.com/eric-king/BingoEngine/issues/1#issuecomment-1470780562, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRQHVBTTFRZS6ZZS5FROETW4IPRZANCNFSM6AAAAAAV35MH64 . You are receiving this because you authored the thread.Message ID: @.***>

jeffpowerscr commented 10 months ago

im having the same problem? index out of range... vs 2022 windows 11

jeffpowerscr commented 10 months ago

When i cloned the project into VS, i had no issue.. when i downloaded the ZIP file, extracted, and ran the solution file, i got the index error when starting up.

eric-king commented 9 months ago

When i cloned the project into VS, i had no issue.. when i downloaded the ZIP file, extracted, and ran the solution file, i got the index error when starting up.

That's pretty strange. I don't know what would be different between the zip file and cloning.

pr0ctor commented 2 months ago

@eric-king So I think I found the source of the issue but not 100% why it happens depending on if the project is cloned vs downloaded through a .zip file. I am also using Visual Studio 2022 on Windows 10 and ran into this exception after having downloaded the source code as a .zip file.

The issue seems to stem from the Environment.NewLine value and an inconsistency between newlines in the source Pictograms and in the user's Environment.

Here in the screenshot when loading the first pattern Pictogram BlackoutPattern we can see that after hitting line 40, the pictogram.Split(Environment.NewLine) yielded an array that was technically split, but not in the format that we were wanting.

image

This is because on Windows, the Environment.NewLine value resolved to \r\n (carriage return then newline) whereas on unix based systems the value is just \n. We can then see that the values in the Pattern only contain \n so for some reason the \r was stripped out during some part of the git process.

Investigating the whitespace characters in Notepad++ confirms the lack of \r in the source code in this case:

image

When I changed the pictogram.Split(Environment.NewLine) to just pictogram.Split("\n") the code worked perfectly fine in my case. I think that there can be a few solutions to this issue depending on the approach that you're wanting to take. One way could potentially be replacing the Environment.NewLine with an adjusted pictogram.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.TrimEntries). This will split on any of the given values and trim the resulting string.

I wasn't able to publish a branch with this change or open a PR but this should fix the issue.