MoaidHathot / Dumpify

Adding `.Dump()` extension methods to Console Applications, similar to LinqPad's.
MIT License
959 stars 40 forks source link

Character encoding problem in PowerShell (rare & intermittent) #25

Open dgilleland opened 5 months ago

dgilleland commented 5 months ago

I'm "re-using" Dumpify as a way to do a quick'n'dirty representation of a 2D array of char values for a BattleShip concept. It's just a temporary usage for a concept presentation. But I've noticed a very rare and unpredictable messing up of the border characters every once in a while when I run my code (even without code changes). Here's what I'm seeing.

image

When it happens, it's not always those incorrect characters - sometimes it's different ones. Again, this is quite rare and hard to reproduce. The code usage is quite simple (.NET 8 console app, running in PowerShell, on Windows 11):

void Concept()
{
    char[,] grid = new char[10,10];
    // Initialize
    for(int row = 0; row < 10; row++)
        for(int col = 0; col < 10; col++)
            grid[row,col] = Random.Shared.Next(10) switch
            {
                < 7 => ' ',
                >= 7 and < 9 => '-',
                _   => Random.Shared.Next(5) switch
                {
                    < 4 => '-',
                    _ => 'H'
                }
            };

    grid.Dump("Player Won");
}
MoaidHathot commented 5 months ago

Hi, thanks for reporting this! I will try to reproduce it to look further into it, although it is more likely to be a bug in Spectre.Console.

MoaidHathot commented 5 months ago

@dgilleland, I tried running the code in a loop for 5-10 minutes but it didn't reproduce for me. Does it still reproduce for you?