I have a thread monitoring the Joystick that seems to be killing TinyCore for some reason. I can confirm it is exactly this method, since it is a small app and removing this removes the problem.
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
new Thread(MonitorJoystick).Start();
}
void MonitorJoystick()
{
RetroConsole.Buttons md;
long lNextOccur = 0;
long[] Delays = new long[] { 750 * TimeSpan.TicksPerMillisecond, 500 * TimeSpan.TicksPerMillisecond, 300 * TimeSpan.TicksPerMillisecond, 150 * TimeSpan.TicksPerMillisecond, 75 * TimeSpan.TicksPerMillisecond, 25 * TimeSpan.TicksPerMillisecond, 10 * TimeSpan.TicksPerMillisecond };
int DelayIndex = 0;
while (true)
{
md = RetroConsole.Buttons.None;
Joystick.Position jp = joystick.GetJoystickPosition();
if (jp.X < 0.4)
md = RetroConsole.Buttons.Left;
else if (jp.X > 0.6)
md = RetroConsole.Buttons.Right;
else if (jp.Y < 0.4 && jp.Y < jp.X)
md = RetroConsole.Buttons.Down;
else if (jp.Y > 0.6 && jp.Y > jp.X)
md = RetroConsole.Buttons.Up;
if (_jMD != md)
{
if (_jMD != RetroConsole.Buttons.None)
RC.SendButtonPress(md);
else
RC.SendButtonPress(_jMD);
_jMD = md;
DelayIndex = 0;
lNextOccur = DateTime.Now.Ticks + Delays[DelayIndex];
}
else if (md != RetroConsole.Buttons.None && DateTime.Now.Ticks >= lNextOccur)
{
RC.SendButtonPress(_jMD);
if (DelayIndex < Delays.Length - 1)
DelayIndex++;
lNextOccur = DateTime.Now.Ticks + Delays[DelayIndex];
}
Thread.Sleep(250);
}
}
Resultant error:
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (6) ####
#### Message:
#### Microsoft.SPOT.Application::OnEvent [IP: 0098] ####
#### Microsoft.SPOT.EventSink::ProcessEvent [IP: 0023] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
A first chance exception of type 'System.NullReferenceException' occurred in Microsoft.SPOT.TinyCore.dll
Any clue here? It tells me not to use blocking While/Trues but I’m inside a new thread and I sleep, so where’s the issue?