_CrtIsValidHeapPointer fails on globally created object within a static llibrary
添加时间:2008-09-25 原文发表时间:2008-09-25 人气:2
本文章共3360字,分3页,当前第1页,快速翻页:
Hello,
I have a very simple class in a static library which instantiates a global object of it.
Following is a piece of the header.
class
{
MyBoard
public
MyBoard(std::string net_id);
~MyBoard(){}
std::string NetworkId();
:void NetworkId(std::string net_id);
private
std::string NetId;
};
Then on the CPP file I have the following:
MyBoard::MyBoard(std::string net_id)
: NetId(net_id)
{
}
std::string MyBoard::NetworkId()
{
}
return NetId;
void
{
NetId = net_id;
}
MyBoard GlobalMyBoard(
}
When I create a winform application an create one of this objects, I will get an assertion done by :
_CrtIsValidHeapPointer(..)
Now, if the destructor from the class is omitted, then the assertion problem goes away, I have been reading about this and all I am getting is that the destructor is not located on the local heap and MSVC8 is not happy about this.
How do I solve this problem ?, How can this global object be created on the local heap?
I also noticed that if I do not create the global object on my static library class, problem also goes away. I do need to instantiate the global object.
The reason why you get this error is that a winforms application has a managed entry point. The initialization of the native global objects is done by the CRT (C RunTime) startup routine. Since in this case there is no CRT startup routine the MyBoard global object fails to initialize correctly.
If possible, always include the call-stack from the point you get the assert. This will greatly help the investigation. In this case, you can see that the call stack originates from the managed startup code.