tags:

views:

1169

answers:

7

Hello,

I'm trying to generate a release build for a C++ application that I've written. The application runs fine (debug & release) when you run it from within VS2008; but when you run the executable it crashes nearly every single time.

Now, is there a hack so I can run this application as a standalone application without having to run through all of the code and finding the bug that is causing it?

Thanks in advance.

+5  A: 

In short, no.

you will have to find the bug, if it works within VS, then I'd hazard a guess that it is a timing issue, possibly you're overwriting shared thread data, this would be less likely (though still possible to see) inside VS as its being run in a debug environment which slows it down a bit.

If you want help finding your bug, then tell us more. Otherwise, build your release with debug symbols (pdbs), install DrWatson as the system debugger and run it standalone. When it crashes DrWatson will create a minidump file, load this into WinDbg (my favourite) and you'll be able to see exactly where your bug is (it'll even tell you that the dump contains an exception and show you it by default. You need to add your source code path and path to your symbols in WinDbg to get it to do this correctly).

Then you will also know how to diagnose crashes when the app is run on-site too.

gbjbaanb
We ran an old C++ app in debug mode at our client sites for over 6 years before we finally found the error. Single byte overrun on a buffer, in debug mode it never had a problem for some reason.
Jess
the reason is that debug mode pads all memory allocations with a 4-byte 'guard page' so it can be easy to find buffer overruns. http://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations
gbjbaanb
+1  A: 

Are you loading external resources? If you are check that your relative paths are correct in the C++ program.

20th Century Boy
Relative paths are correct.
Chaoz
+1  A: 

One possibility is that your program uses uninitialized heap data. Launching a program from the debugger enables the NT debug heap, which causes the heap allocator to fill new memory blocks with a fill pattern, and also enables some heap checking. Launching the same program from outside the debugger leaves the NT debug heap disabled, but if the program was linked against the debug version of the C runtime, then the CRT debug heap will still be enabled.

A much less likely possibility is that your program requires SeDebugPrivilege to be set in its process token. The debugger enables this privilege in its process token, which has the side effect that all programs launched from the debugger inherit this privilege. If your program tries to use OpenProcess()/ReadProcessMemory()/WriteProcessMemory() and doesn't handle errors correctly, it's conceivable that it could crash.

bk1e
A: 

There are a few possibilities. Besides what has already been mentioned, running an app from Visual Studio will execute in the same security context as the Visual Studio instance. So if, for instance, you are working on Vista, you might be hitting an unhandled security violation if you're trying to access protected files, or the registry.

What if you build a debug version and run it standalone? Does it crash? If so, you can usually break into the debugger from there and get a call stack to see what the malfunction is.

Gerald
Debug version runs fine
Chaoz
Okay, then it's probably some uninitialized pointers. You should go through your code and make sure everything gets initialized, all pointers to NULL, etc. And/or build a hybrid version; all release mode settings with debug symbols enabled, and see if you can get a call stack for the crash that way.
Gerald
A: 

From the details you've given, it sounds like there may be a library issue. Are you running the program on the same computer? If not then you'll also have to deploy the appropriate libraries for your application. If you are running on the same computer but outside of the dev environment, ensure that your application can see the appropriate libraries.

nathan
Application is run on the same computer; library wise the application should be fine.
Chaoz
A: 

Best way i have found to debug in release is to create a crash dump when an crash happens and the dump then allows me to load debug symbols on my dev computer and find out whats going on. More info here: http://www.debuginfo.com/articles/effminidumps.html

Lodle
A: 

You can also go to file => open in Visual Studio and open the .exe, so you are not starting it under the debugger per se. Not sure if it will help.

http://blogs.msdn.com/saraford/archive/2008/08/21/did-you-know-you-can-debug-an-executable-that-isn-t-a-part-of-a-visual-studio-project-without-using-tools-attach-to-process-296.aspx

Mark Sowul