I have this code that crash only in Release:
int main()
{
MyStruct s;
s.field = bla;
xTaskCreate(TestTask, "TestTask", 2000, &s, 1, 0);
// other tasks creation
vTaskStartScheduler();
}
void TestTask(void *p)
{
// some delay
MyStruct* s = (MyStruct*)p;
another_func(s->field); // hard fault
}
I manage to fix it like this:
int main()
{
MyStruct* s = new MyStruct();
s->field = bla;
xTaskCreate(TestTask, "TestTask", 2000, s, 1, 0);
// other tasks creation
vTaskStartScheduler();
}
I don't understand why. Did I fixed it or workaround a memory corruption that can still be there?
Thanks.