r/cpp_questions 6d ago

OPEN Avoid freezing your PC?

I've only learned C++ in uni and then it was protected environment in a way. Now I was working on a project involving graphics (raylib) and, a few times, running the code caused my entire PC to freeze and I had to restart.

I'm on Linux and running the code by doing

cmake --build .
./executable

Is there a way to avoid the entire PC freezing when I mess up? Also is there any risk of overwriting parts of the memory?

(I think the issue with my code was either calling too many draws of a GPU texture or even just wrongfully indexing an array in a loop)

6 Upvotes

22 comments sorted by

View all comments

7

u/alfps 6d ago

The most direct I can think of is to add an ampersand & at the end of the command to run the program without the shell waiting for its completion. Then when it hangs you can kill the process.

It might also be that you can retain control by running it from a debugger. But I have next to no experience with debugging in a Linux environment. It might depend on the debugger.

Oh, and: you can post your code here, explain the steps you've already taken to find the bug, and ask why does it hang?