Crash on calling millis() before entering main()
end2endzone opened this issue · comments
A possible crash can occurs when executing Arduino examples using win32Arduino. If an example creates a static variable or a class which calls a timing function (i.e. millis()
) during initialization, then win32Arduino timing strategy might not be initialized yet which creates a null pointer exception in arduino.cpp, line 714.
The issue is certainly related to a race condition between the initialization of the sketch example variable and win32Arduino’s timing strategy initialization.
One workaround is to add the following code before the sketch variable declaration:
#include "IncrementalClockStrategy.h"
bool init()
{
//force incremental clock strategy of win32Arduino library
testarduino::IncrementalClockStrategy & wClock = testarduino::IncrementalClockStrategy::getInstance();
testarduino::setClockStrategy(&wClock);
return true;
}
static bool _initialized = init();