Having trouble with 'System.AccessViolationException' while developing a WindowsPhone8 app and don't know how to deal with it. Here is GitHub repo.
Exception appears when app tries to access (assign value 5) int
field of an object ("value") of a class ("SudokuCell") in a class ("SudokuSection") in a class ("SudokuField").
testSudokuField.AddValueToSingleCell(5, new Tuple<int, int>(i, j)); // class MainPage
public class SudokuField
{
public SudokuSection[,] Sections;
public SudokuHorizontal[] Horizontals;
public SudokuVertical[] Verticals;
public bool solved;
public void AddValueToSingleCell(int value, Tuple<int, int> coords) // Item1 - horizontal, Item2 - vertical
{
var temp = InterpretCoordsForSection(coords);
this.Sections[temp.Item1 - 1, temp.Item2 - 1].ChangeCellValue(value, temp.Item3, temp.Item4);
this.Horizontals[coords.Item1 - 1].cells[coords.Item2 - 1].value = value;
this.Verticals[coords.Item2 - 1].cells[coords.Item1 - 1].value = value;
}
public class SudokuSection
{
public SudokuCell[,] cells;
// --------- Constructors
public SudokuSection()
{
this.cells = new SudokuCell[3, 3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
this.cells[i, j] = new SudokuCell();
}
public void ChangeCellValue(int value, int x, int y)
{
this.cells[x-1, y-1].ChangeValue(value);
}
}
public class SudokuCell
{
public int value; // Exect value of a cell
public SortedSet<int> acceptableValues; // A of acceptable values of a single cell
// --------- Constructors
public SudokuCell() // Empty constructor
{
this.acceptableValues = new SortedSet<int>();
}
public SudokuCell(int value) // Constructor for a cell with an exect value
{
this.value = value;
}
// --------- Methods
public void ChangeValue(int value)
{
this.value = value;
}
}
I tried to explain the issue maximally understandable. Will be grateful if you just point me to a solution.