none
Runtime crash error when running a Release executable RRS feed

  • Question

  • I am working on a VS2008 C# .NET 3.5 application with a C++/CLI wrapper of a native C++ graphics system that is using DirectX9. Both the C++/CLI wrapper and native systems are in their own DLLs. The window I am using to initialize DirectX9 is the Handle of a System.Windows.Form.

     

    The particular problem I am running into is when I attempt to pull down the C++ graphics system and re-initialize it.  Pulling down the C++ system incorporates deleting everything in the system (including the DirectX device) so it can be re-initialized as if the system was never initialized in the first place.

     

    When running Release in VS2008, I am able to tear down and reinitialize the system as many times as I please in the same application (I tried about 20 times before I got bored).  However, when I run from the executable in the bin directory, I cannot re-initialize the system.  It crashes with an "Attempted to read or write protected memory error". I have put log messages in all over the initialization, as well as some inner functions that are being called inside the initialization.  According to my log statements, the crash occurs in between two log messages (i.e., there is no code being executed except for the logging itself), which doesn't help me at all.  The more logging I put in, the further the initialization goes (it initializes more subsystems than previously with more log messages). I am guessing it is some time-sensitive issue.

     

    Running an "identical" C++ application (uses the system in the same way, just doesn't have to go through the C++/CLI wrapper system), I am able to run the Release build from the executable and re-initialize the system, so it appears to be an issue with the C# or C++/CLI.

     

    DirectX does not report any COM leaks when tearing down the system, and I have done my due diligence to make sure there are no COM leaks. I can say with a lot of confidence that there are no COM leaks.

     

    I have tried all the suggestions in this related post, with no effect on my issue:

    http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/6adca20b-649f-41a4-8fa1-09534882d76c

     

    I know this is a "common" issue across the forums, and it is certainly a unique situation I am running with. There is a lot going on in cleaning up and initializing this system and it may just be one of those things that is near impossible to solve.  Any help is appreciated.  I cannot be too specific about what exactly I am working on, but I will do what I can to explain further, if necessary.

     

    Thank you,

    Adam

    Monday, May 17, 2010 3:26 PM

Answers

  • AVs are sometimes hard to track down. You can find out where exactly the AV happens - just attach debugger when your process crashes and check out the call stack.

    COM interop and native components are usual suspects for this kind of errors. I guess there is some bug hidden somewhere that corrupts memory. Moreover uninitialization is typically very poorly tested scenario, so I am not that much surprised you are hitting AV in that situation.

    The fact that your app works under VS Release just means that the memory corruption is sensitive to where in memory and how your app is exactly loaded. Try to disable the VS host in your project properties - that might make it closer to your "run from bin directory" scenario.

    -Karel

    • Marked as answer by SamAgain Friday, May 21, 2010 12:41 PM
    Tuesday, May 18, 2010 4:14 AM
    Moderator