<p>I have a workspace for running an H.263 Video Encoder in a loop for 31 times i.e. the main is executed 31 times to generate 31 different encoded bit streams. This MS Visual Studio 2005 Workspace has all C source files. When i create a "DEBUG" configuration for the workspace and build and execute it, it runs fine, i.e. it generates all the 31 output files as expected.
But when I set the configuration of the workspace to "RELEASE" mdoe, and repeat the process, the encoder crashes at some test case run.</p>

<p>Now to debug this is verified following:</p>

<ol>
<li>Analyzed the code to see if there was any variable initialization being missed out in every run of the encoder </li>
<li>Checked the various Workspace(Solution) options in both the modes (DEBUG and RELEASE). </li>
</ol>

<p>There are some obvious differences, but i turned the optimization related options explicitly same in both modes. </p>

<p>But still could not nail the problem and find a fix for that. Any pointers?</p>

<p>-Ajit.</p>

[{'answer_id': 8615, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 0, 'selected': False, 'text': "<p>Are you sure there are no precompile directives that, say, ignores some really important code in Release mode but allows them in Debug?</p>\n\n<p>Also, have you implemented any logging that might point out to the precise assembly that's throwing the error?</p>\n"}, {'answer_id': 8616, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 3, 'selected': True, 'text': "<p>It's hard to say what the problem might be without carefully inspecting the code. However...</p>\n\n<p>One of the differences between debug and release builds is how the function call stack frame is set up. There are certain classes of bad things you can do (like calling a function with the wrong number of arguments) that are not fatal in a debug build but crash horribly in a release build. Perhaps you could try changing the stack frame related options (I forget what they're called, sorry) in the release build to the same as the debug build and see whether that helps.</p>\n\n<p>Another thing might be to enable all the warnings you possibly can, and fix them all.</p>\n"}, {'answer_id': 8617, 'author': 'John Smithers', 'author_id': 1069, 'author_profile': 'https://Stackoverflow.com/users/1069', 'pm_score': 1, 'selected': False, 'text': '<p>Could be a concurrency problem of two threads. The DEBUG configuration slows the execution down, so the problem does not occur. But, only a guess.</p>\n'}, {'answer_id': 8618, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 1, 'selected': False, 'text': '<p>Interesting problem.. Are you sure you have no conditional compilation code lurking around that is not being compiled in release mode? i.e:</p>\n\n<pre><code>#if (DEBUG)\n// Debug Code here\n#else\n// Release Code here\n#endif\n</code></pre>\n\n<p>Thats the only thing I can really think of.. Never experienced anything like this myself..</p>\n'}, {'answer_id': 8643, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 0, 'selected': False, 'text': "<p>I would look at the crash in more detail - if it's crashing in a test case, then it sounds pretty easily reproducible, which is usually most of the challenge.</p>\n"}, {'answer_id': 8644, 'author': 'David Sykes', 'author_id': 259, 'author_profile': 'https://Stackoverflow.com/users/259', 'pm_score': 1, 'selected': False, 'text': '<p>Can you add the debug symbols to the release build and run it in the debugger to see where and why it crashed?</p>\n'}, {'answer_id': 8661, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Another thing to consider: in debug mode, the variables are initialized with 0xCCCCCCCC instead of zero. That might have some nasty side effects.</p>\n'}, {'answer_id': 8788, 'author': 'Coincoin', 'author_id': 42, 'author_profile': 'https://Stackoverflow.com/users/42', 'pm_score': 1, 'selected': False, 'text': "<p>Yeah, those bastard crashes are the hardest to fix. Fortunatly, there are some steps you can do that will give you clues before you resort to manually looking at the code and hope to find the needle.</p>\n\n<p>When does it crash? At every test? At a specific test? What does that test does that the others don't?</p>\n\n<p>What's the error? If it's an access violation, is there a pattern to where it happens? If the addresses are low, it might mean there is an uninitialised pointer somewhere.</p>\n\n<p>Is the program crashing with Debug configuration but without the debugger attached? If so, it's most likely a thread synchronisation problem as John Smithers pointed out.</p>\n\n<p>Have you tried running the code through an analyser such as Purify? It's slow but it's usually worth the wait.</p>\n\n<p>Try to debug the release configuration anyway. It will only dump assemblies but it can still give you an indication of what happens such as if the code pointer jumps in the middle of garbage or hits a breakpoint in an external library.</p>\n\n<p>Are you on an Intel architecture? If not, watch for memory alignement errors, they hard crash without warning on some architectures and those codec algorithm tend to create those situations a lot since they are overly optimized.</p>\n"}]
['https://Stackoverflow.com/questions/8612', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2759376/']