1

I compiled a program using freeglut, optix, cuda and other libraries (some of them dinamically loaded). It compiles and runs without problems in Visual Studio but it crashes if I execute it outside Visual Studio. Both release and debug versions work within VS, they both crash without any information on Windows 8 if I try to execute them directly.

I already included all the necessary DLLs, that didn't work.

What could be the problem?

Marco A.
  • 43,032
  • 26
  • 132
  • 246
  • 2
    maybe you could compare the environment that visual studio has against the the default environment? (path, dependency walker - seems to ALWAYS be the case for me). – Son-Huy Pham Jul 02 '13 at 19:19
  • Damn you were right.. there was a path missing.. make it an answer and I'll accept it. – Marco A. Jul 02 '13 at 19:21
  • Try to check your code using by the Viva64 rule set: http://www.viva64.com/en/viva64-tool/ –  Jul 12 '13 at 06:22

4 Answers4

3

Most such observations are usually coming from undefined behavior -- using uninitialized variable, dangling pointers/refs, overrunning buffer.

You may try to use Application Verifier, with some luck it might rearrange the used memory enough for you to trigger the problem under debug to help corner it.

Also, when it crashes you should get a prompt to launch VS and inspect the problem -- did it not indicate a hint? What was the immediate cause of the crash and what you had on the call stack there?

Balog Pal
  • 16,195
  • 2
  • 23
  • 37
2

You can try comparing the environments between visual studio and the default environment.

Dependency walker should identify any missing DLLs.

Son-Huy Pham
  • 1,899
  • 18
  • 19
  • This will most likely not help, unless his debug build is significantly different. Far more likely is that his compiler created significantly different code, OR his debug heap (always on in VS) is protecting him. – Daniel Goldberg Jul 03 '13 at 13:23
  • This might be what solved his problem, but this wouldn't be the first thing I'd try, nor is it the main difference between the environments. – Daniel Goldberg Jul 04 '13 at 19:37
2

Get WinDBG, then File > Open Executable and run the program under WinDBG. When it crashes, you will get some more information. My answer here describes an issue in .net, but the concept applies to native C++ as well.

Community
  • 1
  • 1
Michael Stum
  • 177,530
  • 117
  • 400
  • 535
1

Visual studio runs executables under "debug" mode, meaning a debugger is present.

What does this mean? If you check out the msvcrt implementation, if the runtime detects a debugger is present (IsDebuggerPresent), then heaps preform differently.

What does this mean? It means buffer sizes are "nudged" upwards, it means memory allocations are wiped clean by default (no need to memset), etc.

This can cause a variety of bugs to manifest, or some more subtle bugs to be hidden.

Daniel Goldberg
  • 19,908
  • 4
  • 21
  • 29