samedi 7 juillet 2018

C# algorithm freezes while C++ does not [on hold]

I am porting a Sudoku generating algorithm from C++ (SDL) to C# (Windows Forms) and there is one difference: the C++ algorithm never freezes, but the C# algorithm freezes after generating only a couple playable Sudoku grids. I am using Visual Studio 2017. The algorithms are EXACTLY the same. There is absolutely no reason I can think of that explains why Windows Forms freezes.

I pinpointed the "freeze" to an infinite loop where the algorithm keeps restarting a row (erasing and filling in again) when a counter variable goes above 150 iterations, but this infinite loop should never happen because there is an if statement that prevents any row from being restarted more than 150 times (it also resets the counter to 0 and iterates a second counter). After debugging, I clearly see that the number of iterations that counter goes through is above 150, more like a few thousand.

Even if the algorithm needs to restart the second row more than 150 times, it is programmed to restart the whole grid if it has to do that. But it does not restart the whole grid when it freezes. It keeps restarting the same row over and over again, more than 150 times. I cannot explain this. What is going on? It is disobeying its own code!!!

Aucun commentaire:

Enregistrer un commentaire