gpt4 book ai didi

c++ - FreeRTOS 仅在 Release 中崩溃

转载 作者:搜寻专家 更新时间:2023-10-31 01:28:49 24 4
gpt4 key购买 nike

我的代码仅在发布时崩溃:

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
}

我设法像这样修复它:

int main()
{
MyStruct* s = new MyStruct();
s->field = bla;
xTaskCreate(TestTask, "TestTask", 2000, s, 1, 0);

// other tasks creation
vTaskStartScheduler();
}

我不明白为什么。我是否修复了它或解决了仍然存在的内存损坏问题?

谢谢。

最佳答案

我傻了,FreeRTOS的文档上写的: https://www.freertos.org/a00125.html

so it is not valid to pass the address of a stack variable.

关于c++ - FreeRTOS 仅在 Release 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51173936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com