Qt Creator编译调试项目出现Invalid parameter passed to C runtime function.
由于是多线程环境和Qt Creator无法调试dump,调试定位源码特别困难,一直难以解决。
最后再试了一个办法后,终于定位了源码。
编译器: Qt Creator
问题定位办法:使用set_new_handler, 回调函数中打断点,准确找到错误的源码位置!
问题结论:发现内存申请失败了,被使用了空指针,导致Invalid parameter passed to C runtime function.
附加:set_new_handler使用代码范例(网上抄的)
// new_handler example
#include <iostream> // std::cout
#include <cstdlib> // std::exit
#include <new> // std::set_new_handler
void no_memory () {
std::cout << "Failed to allocate memory!\n";
std::exit (1);
}
int main () {
std::set_new_handler(no_memory);
std::cout << "Attempting to allocate 1 GiB...";
char* p = new char [1024*1024*1024];
std::cout << "Ok\n";
delete[] p;
return 0;
}
参看文章:
https://blog.csdn.net/wzxq123/article/details/51502356
https://blog.csdn.net/ixiaochouyu/article/details/47812761