Solved return 0; causes runtime error. Please help. ;_;
-
Can you share your complete main function ?
-
TL; DR: Comments are German and the program is supposed to restart the computer and has certain control loops to abort the process if wished so.
Yeah sure! :) My varible names are English, my comments are German tho... But I can tell you what my program roughly does. It's supposed to restart the computer every time it is executed (For testing purposes it'll restart in 166 minutes or so, so I have time to stop the process with cmd.) But I added a loop which lets me abort the process with Numpad0+Numpad1 if needed. In another thread runs a timer which will continue the program if the shortcuts aren't pressed in a certain amount of time. The length of the timer should also be dynamic - the first time it shall be 60 seconds (60000 ms) and create a file where the length of the next timer is written in (55000ms = 60000ms-5000ms). That's all for now. I'm currently working on the File part. :)
When I made this thread this section didn't exist tho and everything worked fine (except the crash at the end!). And now with the addition of these lines obviously nothing has changed.
But I don't wanna keep babbling all night long. ;) Here's my code:
Edit: Finished the file part. This part should work now. (Updated the code here, too). Still having the problem with the error message, though.
#include "Header.h" int main(int argc, char *argv[]) { QApplication PermaRestart(argc, argv); /*Notice: I initially posted my main here. I removed it again after my problem has been solved.*/ return 0; }
-
Still having the problem. Nobody able to offer a solution? :S
-
This post is deleted! -
After a bit of expermimenting with already working console programs which use
return 0;
, I finally found the solution myself:When using
std::thread
it seems to be a must to use thejoin()
function somewhere after the start of the thread. I wasn't usingjoin()
for every of my threads because I already made it finish before callingreturn 0;
with my program flow. And how I might experience: Not usingjoin()
causes an "unexpected terminate without active exception" message.Confusingly I have never read about this absolute necessity of
join()
in all the C++ references I visited... They should add this as notice in my opinion. (Or I'm just blind, lol.)Moderators can mark this as solved! ^.^
Thynome
-
Please practice some patience, allow at least 24 hours before bumping your own thread. This forum is community driven and not all members live in the same timezone as you.
As for your problem, first: why are you using so much heap allocated objects ? Then: what does your threads do ?
-
Post crossed :D
Glad you found out :)
You can mark the thread solved yourself with the "Topic Tool" button :)
Happy coding !
-
@SGaist Sorry I bumped it but some random Korean guy made about 2 pages of spam threads and I was afraid to get forgetten. ;)
For the heap allocated objects: You're meaning the ones using
new
anddelete
don't you (Sorry, I started coding 6 - 7 months ago so I don't know all the professional words yet. ^^)? If you mean them, I'm using so many because in my code they completely replace my normal varibles. They just allow me more control over my program and (I know, it's absolutely not relevant in these scales.) better performance. I know about just using normal varibles and using call by reference with&
if necessary but I personally find it confusing comparing to my dynamic pointers. :) -
He got lucky today…
Don't worry about them.
Better performance ? Not necessarily: you deference these pointers most of the time so it's not really what's best for performance.
Since you're starting, take the time to study C++11, there are some pretty good books worth reading, especially if you're starting.
-
@SGaist Can you recommend some in particular? I've already read some basic ones when I learned programming C from scratch but I'm interested in your opinion. If possible they shouldn't be too hard to read because my English is still not as good as my German. ^^
-
You can find some good references here and Effective Modern C++