12-14-2003, 10:30 PM | #1 (permalink) |
Riiiiight........
|
C++ crashes..... after it executes the last line in main()
so I have my C++ program, everything works fine. It even gives me output.
the last lines of my code in main() are char x; cin>>x; its just to keep the window open until i press a key to allow the program to close. but when i enter a character and press enter, it crashes.. or rather. windows says it crashes... when i delete the cin, it just crashes on termination, WHY??!!!! thanks....... just about going crazy with this... |
12-14-2003, 11:36 PM | #2 (permalink) |
Junkie
Location: North Hollywood
|
something else is going on cin>>x; probably isn't the cause, probably a stack overwrite, or buffer overrun.
while (!kbhit()); // Waits for keystroke will also work or getch use conio.h but replacing the cin will likely just cover up the real cause. |
12-15-2003, 01:22 AM | #5 (permalink) | |
Pure Chewing Satisfaction
Location: can i use bbcode [i]here[/i]?
|
Quote:
__________________
Greetings and salutations. |
|
12-15-2003, 07:42 AM | #6 (permalink) |
I am Winter Born
Location: Alexandria, VA
|
As I posted in the same thread in Knowledge:
I've had this sort of thing happen to me when I've got dynamic memory allocated that I never properly clean up after. Make sure if you allocate dynamic memory in your program, you free/delete it properly before the end of the program, and that all of the destructors for your classes are working properly.
__________________
Eat antimatter, Posleen-boy! |
12-15-2003, 09:29 AM | #7 (permalink) |
Riiiiight........
|
Thanks guys. I tried returning values at the end of main, but it still doesnt help.
Even though I'm pretty new at this, I've been careful to clear delete objects my pointers are pointing to before i reassign or delete the pointers. Here's a bit more information. the size of my vectors and arrays are mostly equal to a parameter i enter in, "totalPeriods". Now, the program works fine up to totalPeriods=20. then the funny termination error creeps in when i increase it beyond that. I read in command line arguments to run my program, and i check that the arguments are correct. (well.. they should be, since the program runs and writes the output to a text file and all. ) I don't think anyone wants to wade through my 1000 lines of code right? Any volunteers are most welcome though... |
12-15-2003, 12:31 PM | #9 (permalink) |
Junkie
Location: North Hollywood
|
i don't think its return types on a main, that won't crash VC, technically only int is a valid return type, but VC allows void happily, neither will not releasing memory. releasing memory twice might cause a crash, or releasing the wrong block of memory.
I'm betting its stack corruption, if its crashing at the end of main and its not in a destructor, the stack has probably been upset. What does the debugger say ?, it should stop you exactly at the point it crashes with hopefully a useable stack trace, if you don't know how to debug, run it in the debugger, switch on the call stack, registers etc and take a readable screen shot and post it Are you using local variables of a fixed size to read data into ? I'll also be happy to help you if needed, perhaps zip up your project and post it somewhere if you can Last edited by charliex; 12-15-2003 at 12:35 PM.. |
12-15-2003, 06:06 PM | #11 (permalink) |
Riiiiight........
|
PHP Code:
Last edited by cheerios; 12-16-2003 at 10:23 PM.. |
12-15-2003, 06:15 PM | #12 (permalink) |
Riiiiight........
|
PHP Code:
Last edited by cheerios; 12-16-2003 at 10:24 PM.. |
12-15-2003, 06:16 PM | #13 (permalink) |
Riiiiight........
|
for some reason the code tags don't like the things i put between < >.
sorry for using so many global variables. I know I should have encapsulated them a whole lot more, and written "safer" code, but we were in a big hurry.... so if anyone gets irritated reading the code, heh.. apologies in advance... Last edited by dimbulb; 12-15-2003 at 06:20 PM.. |
12-15-2003, 11:04 PM | #15 (permalink) |
WARNING: FLAMMABLE
Location: Ask Acetylene
|
Ay caramba, it's bigger then I thought!
Okay, have you tried it out in the debugger? I wouldn't be able to spot the problem in something this big that uses libraries I can't see (ie I don't know the function headers). Off the cuff your main should return 0. If a function in c/c++ returns an integer to indicate success then it should be zero. A non-zero integer is usually used to mean failure. That isn't the issue though. What type of crash do you get? The exact error message? And can you post the full code somewhere so I can copy/paste and run it? What is the output you get? We still don't have enough info to easily spot it.
__________________
"It better be funny" |
12-16-2003, 11:49 PM | #20 (permalink) |
Junkie
Location: North Hollywood
|
theres a couple of small things i see so far, not likely to crash though,
in Simulate() it says PHP Code:
also it should be fstream not fstream.h, you might be getting away with that on vc7/net i'm guessing. need customer .h too and customer.cpp if there is one. |
12-17-2003, 10:01 AM | #22 (permalink) |
Insane
Location: West Virginia
|
since you are using namespace std, you can use the following to easily take care of getting keypresses from the user:
system("pause"); It will automatically put in the text notifying the user a keypress is needed also. As for the question you're asking - I dont see anything wrong so far except for the return 1 =/ Good Luck though
__________________
- Artsemis ~~~~~~~~~~~~~~~~~~~~ There are two keys to being the best: 1.) Never tell everything you know |
12-17-2003, 01:37 PM | #23 (permalink) |
Riiiiight........
|
Thanks everyone. Does anyone have hosting? if not i'll just zip it up and email it to anyone who supplies me with their email.
Small problem. I inherited this program from someone else, though i basically made huuuge changes to it, and it compiles in this little compiler he passed to me as well, called Dev-C++, i think it runs off Gnu or whatever...( as you can see.. i'm a dummy at this... sigh..... i should have done this in Java or Matlab.....) It doesn't compile in Microsoft Visual C++, it gives errors on the iostream stuff, even though i'm not sure why.... Thing is that this program works on a P2 400, on Windows NT. It crashes when totalPeriods is set to more than 20 on machines running windows2000 or windowsXP. WHY TWENTY!!???@@!!! well.. its the last day i'll be working on it. I'll be officially handing it over tommorrow, though i will probably try to find errors in the code. charliex and kel and whoever, I'd appreciate it if you'd PM me your email addresses...... or if someone would host for me... =) |
12-17-2003, 01:40 PM | #24 (permalink) |
Riiiiight........
|
PHP Code:
|
12-17-2003, 01:43 PM | #25 (permalink) |
Riiiiight........
|
PHP Code:
|
12-17-2003, 01:44 PM | #26 (permalink) |
Riiiiight........
|
PHP Code:
|
12-17-2003, 01:47 PM | #27 (permalink) |
Riiiiight........
|
basically the RNG and the RNGStream files are really sophisticated state of the art random number generators. The C++ ones arn't all that good..
one more question, how do you debug programs that require command line arguments?? thanks for all your patience!! |
12-17-2003, 02:34 PM | #28 (permalink) |
Junkie
Location: North Hollywood
|
dimbulb, did you see my notes ? that'll allow you to at least compile what you have on visual c, the only other changes you'd have to make for compatibility is not doing
PHP Code:
if you are using gcc to compile gdb is the debugger. also remember to turn off smiles when posting also add the comamnd line you use to test, since its quite long apparently yep its either freeing memory that was never allocated, corrpted or freed twice. Last edited by charliex; 12-17-2003 at 02:55 PM.. |
12-17-2003, 03:08 PM | #29 (permalink) |
Riiiiight........
|
Here's the command line arguments....
C:\Fall2003Henderson\WorkFolder\IpaVar5.exe 1.5 100 1440 24 4 11 20 15 15 26 20 22 22 23 27 27 27 27 27 33 34 51 38 43 43 32 38 30 29 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.3 1.3 1.3 1.3 1.45 1.6 1.75 1.9 2.05 2.05 2.05 2.05 2.05 1.95 1.85 1.75 1.65 |
12-17-2003, 03:37 PM | #30 (permalink) |
Junkie
Location: North Hollywood
|
where to start
PHP Code:
PHP Code:
|
12-17-2003, 03:53 PM | #31 (permalink) | |
Riiiiight........
|
Quote:
|
|
12-17-2003, 05:42 PM | #33 (permalink) | ||
I am Winter Born
Location: Alexandria, VA
|
Quote:
Quote:
The only instance of trouble I'd see is if you were running it through a C instead of C++ compiler - but then you'd get a lot more issues. |
||
12-17-2003, 10:14 PM | #34 (permalink) | |||
Junkie
Location: North Hollywood
|
Quote:
Quote:
Quote:
|
|||
12-19-2003, 12:01 PM | #35 (permalink) |
WARNING: FLAMMABLE
Location: Ask Acetylene
|
Threw it in the debugger blasted Borland... can't figure out how to make it go show me what line the crash occured on. I also for some reason can't get the addresses in the debugger of all the STL classes having their objects destroyed. That is where the bug is. Did you access internal data of an STL object?
Maybe the issue is with the vectors of vectors? I will have to move this to my laptop where I have a familiar debugger.
__________________
"It better be funny" Last edited by kel; 12-19-2003 at 12:19 PM.. |
Tags |
crashes, executes, line, main |
Thread Tools | |
|
|