_CrtIsValidHeapPointer(pUserData) - why is this code broken. (vs2008)<p align=left><font face=Arial size=2>I've created two projects in a fresh solution using Microsoft Visual C++ 2008 (Not Express).</font></p> <p align=left> </p> <p align=left>1. testui (managed Windows Forms Application /clr /MDd) (from the CLR Windows Forms Application template)</p> <p align=left>2. testlib (unmanaged static library /MDd) (from the Empty Project template)</p> <p align=left> </p> <p align=left>The testui application is unmodified but is made to depend on the testlib.  It has had it's driver modified as follows:</p> <p align=left> </p><font color="#008000" size=2><font color="#008000" size=2> <p>// testui.cpp : main project file.</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;stdafx.h&quot;</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;Form1.h&quot;</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;Test.h&quot;</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>using</font></font><font size=2> </font><font color="#0000ff" size=2><font color="#0000ff" size=2>namespace</font></font><font size=2> testui;</p> <p>[STAThreadAttribute]</p></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>int</font></font><font size=2> main(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>array</font></font><font size=2>&lt;System:<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>tring ^&gt; ^args)</p> <p>{</p> <p>Test t;</p> <p></font><font color="#008000" size=2><font color="#008000" size=2>// Enabling Windows XP visual effects before any controls are created</p></font></font><font size=2> <p>Application::EnableVisualStyles();</p> <p>Application:<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>etCompatibleTextRenderingDefault(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>false</font></font><font size=2>); </p> <p></font><font color="#008000" size=2><font color="#008000" size=2>// Create the main window and run it</p></font></font><font size=2> <p>Application::Run(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>gcnew</font></font><font size=2> Form1());</p> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2>return</font></font><font size=2> 0;</p> <p>}</p> <p> </p> <p align=left>Basically identical to the template, just we #include &quot;Test.h&quot; and create Test t;</p> <p align=left> </p> <p align=left>The testlib static library contains only one class as follows.</p> <p align=left> </p> <p align=left>// Test.h</p><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&lt;vector&gt;</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>class</font></font><font size=2> Test</p> <p>{</p> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2>public</font></font><font size=2>:</p> <p>Test(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>void</font></font><font size=2>);</p> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2>private</font></font><font size=2>:</p> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2>static</font></font><font size=2> std::vector&lt;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>void</font></font><font size=2> *&gt; testvec;</p> <p>};</p> <p> </p> <p align=left>// Test.cpp</p><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;Test.h&quot;</p></font></font><font size=2> <p>std::vector&lt;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>void</font></font><font size=2> *&gt; Test::testvec;</p> <p>Test::Test()</p> <p>{</p> <p>}</p> <p> </p> <p align=left>When I run this program it fails with a Debug Assertion Failed! Expression: _CrtIsValidHeapPointer(pUserData) which of course is raised from <font size=2>_ASSERTE(_CrtIsValidHeapPointer(pUserData)); in dbgheap.c</font></p> <p align=left><font size=2></font> </p> <p align=left><font size=2>Why does this happen? &amp;&amp; How do I fix this?  I developed this test case because it is occurring with a very large static library that uses a lot of stl based static member data similar to this test case.  Anyway, for completeness I have attached the output produced by vs2008 when it fails.</font></p> <p align=left> </p> <p align=left>Any help would be greately appreciated.</p> <p align=left> </p> <p align=left>Thanks</p> <p align=left> </p><font size=1> <p>'testui.exe': Loaded 'C:\Documents and Settings\Devel\Desktop\trees\test\testui\Debug\testui.exe', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\mscoree.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcr90d.dll', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcp90d.dll', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcm90d.dll', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\ole32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\user32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\msvcr80.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'</p> <p>'testui.exe': Unloaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\32e6f703c114f3a971cbe706586e3655\mscorlib.ni.dll'</p> <p>'testui.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\msctf.dll'</p> <p>'testui.exe' (Managed): Loaded 'c:\Documents and Settings\Devel\Desktop\trees\test\testui\Debug\testui.exe', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\rsaenh.dll'</p> <p>'testui.exe' (Managed): Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcm90d.dll', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\ba0e3a22211ba7343e0116b051f2965a\System.ni.dll'</p> <p>'testui.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'</p> <p>First-chance exception at 0x7c96c540 in testui.exe: 0xC0000005: Access violation reading location 0x23e7ad1a.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\version.dll'</p> <p>'testui.exe': Unloaded 'C:\WINDOWS\system32\version.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime'</p> <p>testui.exe has triggered a breakpoint</p> <p>The program '[0x184] testui.exe: Managed' has exited with code 0 (0x0).</p> <p>The program '[0x184] testui.exe: Native' has exited with code 0 (0x0).</p></font> <p align=left> </p> <p align=left></font></font></font> </p>© 2009 Microsoft Corporation. All rights reserved.Tue, 11 Aug 2009 15:20:16 Z62db4002-4ebc-4a3a-91ec-9fc702db821ehttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#62db4002-4ebc-4a3a-91ec-9fc702db821ehttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#62db4002-4ebc-4a3a-91ec-9fc702db821etyler000http://social.msdn.microsoft.com/Profile/en-US/?user=tyler000_CrtIsValidHeapPointer(pUserData) - why is this code broken. (vs2008)<p align=left><font face=Arial size=2>I've created two projects in a fresh solution using Microsoft Visual C++ 2008 (Not Express).</font></p> <p align=left> </p> <p align=left>1. testui (managed Windows Forms Application /clr /MDd) (from the CLR Windows Forms Application template)</p> <p align=left>2. testlib (unmanaged static library /MDd) (from the Empty Project template)</p> <p align=left> </p> <p align=left>The testui application is unmodified but is made to depend on the testlib.  It has had it's driver modified as follows:</p> <p align=left> </p><font color="#008000" size=2><font color="#008000" size=2> <p>// testui.cpp : main project file.</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;stdafx.h&quot;</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;Form1.h&quot;</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;Test.h&quot;</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>using</font></font><font size=2> </font><font color="#0000ff" size=2><font color="#0000ff" size=2>namespace</font></font><font size=2> testui;</p> <p>[STAThreadAttribute]</p></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>int</font></font><font size=2> main(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>array</font></font><font size=2>&lt;System:<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>tring ^&gt; ^args)</p> <p>{</p> <p>Test t;</p> <p></font><font color="#008000" size=2><font color="#008000" size=2>// Enabling Windows XP visual effects before any controls are created</p></font></font><font size=2> <p>Application::EnableVisualStyles();</p> <p>Application:<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>etCompatibleTextRenderingDefault(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>false</font></font><font size=2>); </p> <p></font><font color="#008000" size=2><font color="#008000" size=2>// Create the main window and run it</p></font></font><font size=2> <p>Application::Run(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>gcnew</font></font><font size=2> Form1());</p> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2>return</font></font><font size=2> 0;</p> <p>}</p> <p> </p> <p align=left>Basically identical to the template, just we #include &quot;Test.h&quot; and create Test t;</p> <p align=left> </p> <p align=left>The testlib static library contains only one class as follows.</p> <p align=left> </p> <p align=left>// Test.h</p><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&lt;vector&gt;</p></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>class</font></font><font size=2> Test</p> <p>{</p> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2>public</font></font><font size=2>:</p> <p>Test(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>void</font></font><font size=2>);</p> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2>private</font></font><font size=2>:</p> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2>static</font></font><font size=2> std::vector&lt;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>void</font></font><font size=2> *&gt; testvec;</p> <p>};</p> <p> </p> <p align=left>// Test.cpp</p><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>#include</font></font><font size=2> </font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;Test.h&quot;</p></font></font><font size=2> <p>std::vector&lt;</font><font color="#0000ff" size=2><font color="#0000ff" size=2>void</font></font><font size=2> *&gt; Test::testvec;</p> <p>Test::Test()</p> <p>{</p> <p>}</p> <p> </p> <p align=left>When I run this program it fails with a Debug Assertion Failed! Expression: _CrtIsValidHeapPointer(pUserData) which of course is raised from <font size=2>_ASSERTE(_CrtIsValidHeapPointer(pUserData)); in dbgheap.c</font></p> <p align=left><font size=2></font> </p> <p align=left><font size=2>Why does this happen? &amp;&amp; How do I fix this?  I developed this test case because it is occurring with a very large static library that uses a lot of stl based static member data similar to this test case.  Anyway, for completeness I have attached the output produced by vs2008 when it fails.</font></p> <p align=left> </p> <p align=left>Any help would be greately appreciated.</p> <p align=left> </p> <p align=left>Thanks</p> <p align=left> </p><font size=1> <p>'testui.exe': Loaded 'C:\Documents and Settings\Devel\Desktop\trees\test\testui\Debug\testui.exe', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\mscoree.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcr90d.dll', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcp90d.dll', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcm90d.dll', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\ole32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\user32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\msvcr80.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'</p> <p>'testui.exe': Unloaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\32e6f703c114f3a971cbe706586e3655\mscorlib.ni.dll'</p> <p>'testui.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\msctf.dll'</p> <p>'testui.exe' (Managed): Loaded 'c:\Documents and Settings\Devel\Desktop\trees\test\testui\Debug\testui.exe', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\rsaenh.dll'</p> <p>'testui.exe' (Managed): Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcm90d.dll', Symbols loaded.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\ba0e3a22211ba7343e0116b051f2965a\System.ni.dll'</p> <p>'testui.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'</p> <p>First-chance exception at 0x7c96c540 in testui.exe: 0xC0000005: Access violation reading location 0x23e7ad1a.</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\version.dll'</p> <p>'testui.exe': Unloaded 'C:\WINDOWS\system32\version.dll'</p> <p>'testui.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime'</p> <p>testui.exe has triggered a breakpoint</p> <p>The program '[0x184] testui.exe: Managed' has exited with code 0 (0x0).</p> <p>The program '[0x184] testui.exe: Native' has exited with code 0 (0x0).</p></font> <p align=left> </p> <p align=left></font></font></font> </p>Mon, 26 May 2008 11:59:04 Z2008-05-26T11:59:04Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#2c9789a9-ba9a-4192-a6d9-04d6456af67ahttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#2c9789a9-ba9a-4192-a6d9-04d6456af67anobugzhttp://social.msdn.microsoft.com/Profile/en-US/?user=nobugz_CrtIsValidHeapPointer(pUserData) - why is this code broken. (vs2008)<div class=codeseg><font face="verdana,arial,helvetica,sans-serif" size=2>We are not looking at the code you've got that's crashing.  Your static member definition is not correct.  You'll need to post code that reproduces the Access violation exception as shown in your debug output.  Having the debugger stop at that exception with Debug + Exceptions might help you diagnose the problem.</font></div>Mon, 26 May 2008 15:01:12 Z2008-05-26T15:01:12Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#c18d90ec-f66b-41a9-ab50-d66508fc89f3http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#c18d90ec-f66b-41a9-ab50-d66508fc89f3tyler000http://social.msdn.microsoft.com/Profile/en-US/?user=tyler000_CrtIsValidHeapPointer(pUserData) - why is this code broken. (vs2008)<p align=left><font face=Arial size=2>That is all of the code in both of the projects.  There is nothing else.  Commenting out the line Test t; in main stops the exception from occurring.</font></p> <p align=left> </p> <p align=left>I'm happy for you to state that the static member definition is incorrect.  But could you give some explanation, I mean if I thought it was incorrect I would have fixed it before posting.</p> <p align=left> </p> <p align=left>Why isn't it correct?</p> <p align=left>What is the correct way to define a static std::vector&lt;...&gt; member in a class?</p> <p align=left>Less important but still interesting why doesn't the compiler error/warn?</p> <p align=left> </p> <p align=left>By the way here is the callstack if I break for debug when it occurrs.</p> <p align=left> </p> <p align=left>&gt; msvcr90d.dll!_msize_dbg(void * pUserData=0x9e202f1b, int nBlockUse=0x00000002)  Line 1511 + 0x30 bytes C++<br>  msvcr90d.dll!_dllonexit_nolock(int (void)* func=0x9e607abb, void (void)* * * pbegin=0x0012ee18, void (void)* * * pend=0x0012ee10)  Line 295 + 0xd bytes C<br>  msvcr90d.dll!__dllonexit(int (void)* func=0x9e607abb, void (void)* * * pbegin=0x0012ee18, void (void)* * * pend=0x0012ee10)  Line 273 + 0x11 bytes C<br>  testui.exe!_onexit(int (void)* func=0x004055a0)  Line 110 + 0x1b bytes C<br>  testui.exe!atexit(void (void)* func=0x004055a0)  Line 127 + 0x9 bytes C<br>  testui.exe!`dynamic initializer for 'Test::testvec''()  Line 3 + 0x32 bytes C++<br>  [Managed to Native Transition] <br>  testui.exe!_initterm(void** pfbegin = 0x00406148, void pfend = ) Line 130 C++<br>  testui.exe!&lt;CrtImplementationDetails&gt;::LanguageSupport::InitializeNative() Line 534 C++<br>  testui.exe!&lt;CrtImplementationDetails&gt;::LanguageSupport::_Initialize() Line 657 C++<br>  testui.exe!&lt;CrtImplementationDetails&gt;::LanguageSupport::Initialize() Line 855 C++<br>  <a title="mailto:testui.exe!?.cctor@@$$FYMXXZ" href="mailto:testui.exe!?.cctor@@$$FYMXXZ">testui.exe!?.cctor@@$$FYMXXZ</a>() Line 901 + 0x9 bytes C++<br>  [Frames below may be incorrect and/or missing, no symbols loaded for mscorwks.dll] <br>  kernel32.dll!7c839736()  <br>  kernel32.dll!7c809af9()  <br>  kernel32.dll!7c839736()  <br>  kernel32.dll!7c809af9()  <br>  mscoree.dll!7900b1b3()  <br>  kernel32.dll!7c817067()  <br></p> <p align=left> </p> <p align=left>Thanks</p>Mon, 26 May 2008 23:17:11 Z2008-05-26T23:17:11Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#ee494d75-5c9d-41e9-9b67-826564cfa978http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#ee494d75-5c9d-41e9-9b67-826564cfa978RobWWhttp://social.msdn.microsoft.com/Profile/en-US/?user=RobWW_CrtIsValidHeapPointer(pUserData) - why is this code broken. (vs2008)I had a very similar problem with one of my mixed (managed and unmanaged) projects. I was using a Winforms with /clr specified for the GUI side calling into unmanaged code that at some point referenced a ATL header. Supposedly the winforms wizard configures the project by default to skip the CRT startup code when any ATL header file is detected and thus the reason for it crashing at the g_allocator initialization (this problem is not in the console /clr version). The fix below essentially reverses what the wizard does. On a side note, I included instructions below to obtain access to MSFTs symbols for use when debugging which helped me find this one, atleast to the point I knew what to search for in Google.<br><br>Link describing the problem<br>https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99715&amp;wa=wsignin1.0<br><br>Anyhow here was what I had to do: add  __DllMainCRTStartup@12 in Force Symbols Reference section in the Linker section of the project settings.<br><br><br>VS2008 - To configure Symbol Server, open the symbol search path options dialog. (From the Tools menu, click Options. In the left pane of the Options dialog box, Open the Debugging node and click Symbols.) Add the following search path to the search list: http://msdl.microsoft.com/download/symbols. Add a symbol cache directory to the symbol server cache text box. Click OK. <br> Mon, 02 Jun 2008 17:35:26 Z2008-06-02T17:35:26Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#5a96b49b-8608-4cf8-a821-d083b71316cehttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#5a96b49b-8608-4cf8-a821-d083b71316ceddbabichhttp://social.msdn.microsoft.com/Profile/en-US/?user=ddbabich_CrtIsValidHeapPointer(pUserData) - why is this code broken. (vs2008)<p>I had the exact same problem while using a windows forms application with /clr that depended on a static library that referenced an ATL header, and adding __DllMainCRTStartup@12 in force Symbols Reference sectoin in the Linker section of the project worked for me.  Thanks for posting your solution RobWW.</p>Fri, 25 Jul 2008 21:45:41 Z2008-07-25T21:48:52Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#276a9a16-c26b-4672-97ea-bba3f053d7b5http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/62db4002-4ebc-4a3a-91ec-9fc702db821e#276a9a16-c26b-4672-97ea-bba3f053d7b5Al_Shttp://social.msdn.microsoft.com/Profile/en-US/?user=Al_S_CrtIsValidHeapPointer(pUserData) - why is this code broken. (vs2008)I don't know if the context of my application is the same as yours.  However, adding the mentioned symbol allowed my application to run without throwing an exception <span style="font-size:x-small"><span style="font-size:x-small"><span style="font-size:x-small">_CrtIsValidHeapPointer(pUserData)  I am using a VS2008 C++/CLI Winform project that does use the header atlstr.h (used for CString though not using MFC).  I only get the crash as long as atlstr. is used.<br/> <br/> Adding that (</span> </span> </span> __DllMainCRTStartup@12<span style="font-size:x-small"><span style="font-size:x-small"><span style="font-size:x-small">) symbol solved it!<br/> <br/> If I don't put the link in the Symbol Server, can I still use the solution as-is?  Build times are longer with it in as opposed to without.<br/> <br/> Thanks for a huge help<br/> </span> </span> </span><hr class="sig">Jer 29:11Tue, 11 Aug 2009 15:20:15 Z2009-08-11T15:20:15Z