Question

I have a class residing inside of a dll and an exe using that dll. Exe simply creates the class within the dll and call its methods. Everything works fine when compiled in release mode. But if I compile everything (including the OpenCV library my class uses) in debug mode with MDd flag then I get:

Debug Assertion Failed! _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

All of the binaries involved are using the exact same version of the runtime dlls and everything is compiled on the same computer with VS 2008. As far as I understand (based on my debuggings) the problem is the following:

I am creating an instance of my class using the "new" operator in the exe (under main) then as soon as the constructor of my class does something requiring a memory allocation, memory location of the class itself is overwritten as if both the dll and exe are using the same memory space but different "next available position to allocate" offsets. Therefore the dll does not see that there was already an allocation done inside of the exe hence overwriting the memory area my class resides. Clearly this causes a memory problem.

Any idea why can this happen? I tried my best to explain the situation but I can of course provide more info if required.

Thanks in advance.

Was it helpful?

Solution 2

I found out that the problem was 2 public member variables that were missing from the header file of the class by my mistake. When I added them, the problem is solved.

OTHER TIPS

Please check those DEBUG MACROs, It's crucial. Something like ASSERT...

They are compiled when in debug mode.

When you compile code in release mode, debug MACROs are disabled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top