调试错误 ASSERTE(_CrtIsValidHeapPointer(pUserData))

来源:互联网 发布:windows10自带看图软件 编辑:程序博客网 时间:2024/05/01 00:05

[http://blog.sina.com.cn/s/blog_4cca614d010007x9.html]

 

/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
1132: _ASSERTE(_CrtIsValidHeapPointer(pUserData));

 

(1) If you are developing multithread application, be sure to link it with the correct runtime library(/MD, /MT). That what "The pointer MUST come from the 'local' heap." means.
Check what "ruintime library" you use. It should be "Multi threaded (debug ) DLL"

 

(2) Not only must they match, they must both be DLL versions. If they're static versions, each piece (the exe and the dll) will have their own heap and the OP will still be deleting from mismatched heaps.


I'd also be suspicious of general design issues given the way the OP's main program is having to clean up for the dll.

 

You'll get this problem if you use two different run-time libraries, one to allocate the memory and one to de-allocate the memory. Open up the project settings dialog, switch to C/C++ tab, set Category to Code Generation and check the Use run-time library combo box. These must match in any modules that share the task of allocating and destroying memory.

 

只是把 调用程序 和 程序库 都编译成release就不会出现这个问题。

 

本质参考: [http://topic.csdn.net/u/20071116/09/cc675daa-0ab2-4952-99d0-98f3dd717439.html]

1,内存不能跨模块分配和释放,模块分配的内存必须由该模块自己来释放。应该在DLL中再加一个方法,比如MemRelease,主程序调用这个方法来释放内存。

2,就是绕过new和delete,用GlobalAlloc()和GlobalFree()的方法

 

自己:使用opencv 2.0 peopledetect.cpp 时,Debug版本出现该问题,通过更改 C/C++配置 运行时库 多线程调试 DLL (/MDd) 解决了问题

原创粉丝点击