0

I am dealing with a very peculiar problem at the moment: I have an application that is fully working in Debug-Buildmode, whether I run it from the MSVC environment or start the built executable myself. If I build this application in Release-Buildmode, it is fully working when I run it from the MSVC environment, but shows unexpected behavior when I start it myself.

What differences between the Debug and Release mode could be the reason for this behavior, and why do the problems only occur when I start the executable manually?

It's hard to give code, since it is quite a big project and I have absolutely no clue what could be causing the problem. The program flow is basically:

  • Read settings from file (not the problem, double checked the read values, and used an ini- and the libconfig++-library to be sure)
  • Distribute values to seperate classes (double checked the passed values)
  • One of these classes starts a thread (boost::thread) and triggers callback functions on certain events (these do NOT trigger if release build is executed manually)

Something that I could imagine might cause problems, but I am not sure of:

  • Since the classes were written by different people, there is inconsistency between the usage of std::string and std::wstring. I am converting from one to another using std::wstring(s.begin(), s.end()) and vice versa.

Could this be the reason for my problems, and if yes, how do I solve the issue? I would really appreciate some help on this. Thanks in advance.

Update:

  • The program does not crash and variables do not seem to have different values when I use the infamous print-debug method (since in the debugger everything works out fine)
  • I have read that unitialized variables could be causing this issue and triplechecked every variable used by me, and every variable is initialized properly
  • In unit tests, every module I am using works as expected (though I'm not sure I got the border cases right everytime, since I have not written all modules myself).

Update 2:

  • While disabling optimization step by step and bringing the release buildmode closer to the debug buildmode I was able to narrow the problem down: **In the code generation tab, my program works with the Multithreaded-Debug-DLL, not the Multithreaded-DLL, regardless to optimization settings.

This seems to be a nice accomplishment, yet I lack the understanding for this problem.

nikolas
  • 8,707
  • 9
  • 50
  • 70
  • What's exactly the problem? Does program crash? Have you tried do locate the code which triggers those events? Have you fixed completely string inconsistencies? – Bojan Komazec Feb 23 '12 at 11:28
  • Often this is an uninitalized variable that gets diffent random values depending on how the program is started. – Bo Persson Feb 23 '12 at 11:29
  • @Bojan Komazec What do you mean with "fixed completely string inconsistencies"? As stated above, I have to convert std::string to std::wstring several times. – nikolas Feb 23 '12 at 11:57

2 Answers2

1

Add logging, or eliminate some code blocks. This should allow to find where problem arises. For differences look here:

What is the difference between Debug and Release in Visual Studio?

Community
  • 1
  • 1
marcinj
  • 48,511
  • 9
  • 79
  • 100
  • I have implemented logging, but unfortunately I could not tell where the problem is located by that yet. I'll try to strip down everything as you recommend at the moment. When looking at the Debug/Release differences, I wonder why the problem only arises when the application is executed manually (not within the MSVC debugger); could that be caused by optimization as well? – nikolas Feb 23 '12 at 11:53
  • no idea what is the cause of your problem, when using logging use binary search rule: add logging somewhere in the middle of code and check if it shows up, if so then add logging in the first half middle and so on. Also you might try add debuging info to you Release project and start it from debugger, also disable optimizations. – marcinj Feb 23 '12 at 12:02
1

debug do not use optimizations there are optimizations in release mode that is why the exe size is different. Also the libraries used are different even though out of the same codes. you can make release like debug by turning off the optimization options.

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112