|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| KezRst (8) | |||
|
Hello! I've continued to work on a text based RPG I've been making progress on just for practice. I've come up with this problem though that I have searched for everywhere, and can't seem to find an answer to: Everything I have so far runs entirely smoothly. Once my program ends the main function, though, it gives an error that says 'Program has encountered an error and needs to close.' Because there are no compiler errors or warnings, I'm not sure where to start looking to fix this issue. I've messed around a lot with some of the source code which I thought might be the culprit, but so far nothing has worked. Here is my main function for reference:
do_action() returns a vector<string>, each string list being a set of actions which must be performed by do_action upon the next while iteration. 'currentactions' is reset when the final action has been performed. When vector<string> do_action()[0] is something other then "exit", the game runs very smoothly. Once I call "exit", though, it causes the main 'while' game loop to end. This causes the program to end, as it should, only with the error that I described above. I'm not yet very experienced with C++, so I apologize if the information I've given is less then required or off the mark. If anyone has any ideas, I'll be happy to explain anything necessary in further detail. Thanks in advance! - Aaron | |||
|
|
|||
| writetonsharma (1181) | |
|
the error comes at the very last, which means error is coming from some destructor. I think you have messed with some of the objects you have created which are causing the problem during destruction. how big is your program? if its not very big you can post the whole thing. | |
|
|
|
| KezRst (8) | |
|
It's fairly lengthy I suppose, it has 8 classes. Only five of those classes are ever declared so far, the rest I have not programmed the functionality for yet. I could try constructing and destructing some of those classes before the program ends, because of that is the case it would trigger the error and with that it could be narrowed down a little further. | |
|
|
|
| KezRst (8) | |||||
Alright, it must be the destructor of the Player_t class. I tested this using this code:
The system paused, and as soon as I resumed the program gave a debug error. I commented out the destructor of player and ran a close, and it closed without error. Here is the destructor (moved to a new function) for the player object:
It saves the player's statistics and inventory to a file before the game ends so that statistics are kept next time the program is loaded. I've looked through it and I know I'm missing some sort of error but I can't seem to find what. I tried moving it into a new member function, and calling the new member function before the program closed, but that still gave an error. | |||||
|
|
|||||
| KezRst (8) | |||
Alright well this thread I believe is resolved.
In this loop, I am using j as an iterator, but I accidentally iterated i instead of j, which obviously threw everything way off. Now that I changed it to j++, everything works perfectly. Thanks very much for that suggested it definitely helped narrow it down. :) | |||
|
|
|||
| writetonsharma (1181) | |
|
great. in most of the cases its the destructor who is the culprit when the application crashes after main is executed. | |
|
|
|