Click here to Skip to main content
15,884,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

Thanks

[NEW]

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?

[/NEW]
Posted
Updated 11-Sep-12 13:23pm
v3
Comments
Sergey Alexandrovich Kryukov 7-Sep-12 2:31am    
Guessing? No thank you. I have something more useful to do. How about you?
No, this question does not make any sense.
--SA
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
Sergey Alexandrovich Kryukov 8-Sep-12 21:57pm    
Great, you are always welcome... :-)
--SA
[no name] 11-Sep-12 19:55pm    
Solution 1 almost certainly provides your answer (uncontrolled access). Post some code.

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.
 
Share this answer
 
Comments
DrBones69 8-Sep-12 18:31pm    
How do I inspect my variables in debugger? Can you give me a simple walkthrough?
Sergey Alexandrovich Kryukov 8-Sep-12 22:09pm    
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,
--SA
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. :-)
Sergey Alexandrovich Kryukov 9-Sep-12 0:43am    
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.
--SA
Sergey Alexandrovich Kryukov 8-Sep-12 21:59pm    
Reasonable advice, my 5.
--SA
Hi,



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

C++
DWORD WINAPI ThreadProc( LPVOID lpParameter);



Following prototype will cause problem on 64 bit architecture

C++
void WINAPI ThreadProc( LPVOID lpParameter);


You are expected to return status code from the thread function.
 
Share this answer
 
Comments
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.
BillW33 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900