Click here to Skip to main content
12,898,392 members (57,468 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ MFC
I'm trying to debug my app because sometimes I get random results in my number totals from the app. I am not changing any data that the app already has stored to disk, but it seems that I can run the app in debug mode five or six times in a row and end up with crazy numbers or everything works fine. I'm not finding any memory leaks, but I am NOT very good at debugging, YET.



Okay, so I learned the basics about debugging and I still do not know why I was getting various results for the totals, but I did find that transferring data between classes is flawed. I think there are certain circumstances that transferring data gets lost in translation. Let me explain...

I was trying to transfer data from my view class to a dialog class in a for loop, I created a CStringArray in my dialog class and transferred the data from my view like this... dlg.Profit.Add(myData[nPos].m_sProfits) ... and then I created another for loop in my dialog class to sum the profits using _wtof() function. This process worked most of the time, but sometimes it would give an enormous number. To fix this I had to use the _wtof() function and sum these numbers in my view class then transfer my result to the dialog class dlg.Profit_Total = m_nProfit, can someone would explain to me why this is happening this way?

Posted 6-Sep-12 16:14pm
Updated 11-Sep-12 13:23pm
Guessing? No thank you. I have something more useful to do. How about you?
No, this question does not make any sense.
PrafullaVedante 7-Sep-12 4:14am
he he he he he he good one ....
DrBones69 8-Sep-12 18:29pm
Yes, I do have better things to do, like finding my problem. Thanks for your useful input. :P
Great, you are always welcome... :-)
pwasser 11-Sep-12 19:55pm
Solution 1 almost certainly provides your answer (uncontrolled access). Post some code.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Are your threads incrementing / changing any data variables that are "common" to all the threads? If so, are you protecting that variable with some sort of mutual exclusion access. In Windows it would be a mutex or similar object.

Random / different answers are a common symptom of uncontrolled access to shared variables / memory by threads.

The Visual Studion debugger helps you by suspending the other threads while you are debugging / inspecting variables but once you "step", some of the threads may get to run before you get to the break point. That doesn't explain the "random results", unprotected shared variables does explain it.
DrBones69 8-Sep-12 18:31pm
How do I inspect my variables in debugger? Can you give me a simple walkthrough?
Reasonable advice, my 5.
First, set a break point and wait until code executes to it. Code editor has a menu item "Quick watch" in the content menu; click on it to inspect any object. If the caret position points to some object name before you activate "Quick watch", it will be inspected. Also, open one or more of debug windows:
[Main Menu] -> Debug -> Windows, open one of the following: Watch, Autos, Locals, Immediate. You will see what they are when you use a break point or debug step by step, for Watch window, you will need to add symbols to watch. You will see changes as objects displayed change their values.
Look at the [Main Menu] -> Debug menu for a complete set of available operations.

Just a note: development of any somewhat complex code without a debugger is barely possible. You need to use the debugger every time you have a slightest concern about your run-time behavior, and also before asking questions on this forum, so you would be able to answer expert's questions related to your problem.

Good luck,
DrBones69 8-Sep-12 22:57pm
Thank you SA, this is the kind of response I expect from this forum. Although I might not conform to the exact standards of posting questions, I do believe I deserve some leniency for my inadequacies as I am still learning. I wish that I knew as much as you have forgotten, then I might gain some respect here. :-)
As I say, you're always welcome. Hope you can get a grip om debugging pretty fast, as it's very important for your productivity and results.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


1 )Please check what your thread function is returning ......

2 )If you are using Win32 function CreateThread to create threads then Please check the prototype of your thread function.

It should have prototype

DWORD WINAPI ThreadProc( LPVOID lpParameter);

Following prototype will cause problem on 64 bit architecture

void WINAPI ThreadProc( LPVOID lpParameter);

You are expected to return status code from the thread function.
DrBones69 8-Sep-12 18:33pm
I'm not creating threads intentionally, I don't know how yet.
Chuck O'Toole 8-Sep-12 22:25pm
well, if you're not creating threads yourself, then these are threads created by windows on behalf of things you are doing. As such, they will come and go as they wish. Be aware, these threads then have absolutely no impact on why your program is getting random and incorrect answers. You have some other problem and you really need to debug it carefully. As you said in your original posting, you are not providing code and you'd like our best guess. Well, no more guessing until you provide some more concrete details about the failures, how the values are computed, examples of incorrect results, and, of course, code that has the problem. Once you've debugged as far as you can get and posted more info, you'll get more specific help.
DrBones69 8-Sep-12 22:59pm
Thanks, I'm off on a debugging mission. I hope I make it back in one piece! Wish me luck.
CIDev 9-Sep-12 8:38am
I agree with Chuck O'Toole; the thread info that you posted have nothing to do with your problems. You should have posted in your question that you were not doing any threading yourself and not asked us to guess at your code. You can get much faster and more useful answers if you include better information in your questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 12 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100