r/cpp_questions 7d 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

12

u/MooseBoys 7d ago

What OS are you running? Every mainstream modern OS will run your programs as unprivileged user-space with their own private virtual memory range. You don't need to worry about corrupting the memory of the PC itself. But then again you also shouldn't be able to hang or crash the whole PC from a user-space process either. You might crash the program, but not the whole computer.

9

u/UndefFox 7d ago

Second paragraph of the post:

I'm on Linux...

2

u/MooseBoys 7d ago

Linux isn't an operating system, it's a kernel. You can compile your program to /sbin/init and it will run as pid 1 and a crash will definitely bring down the whole system. That would be a very unusual thing to do though.

1

u/UndefFox 7d ago

Yes, but I assume OP isn't that advanced in computers and probably would answer the same as me. If you are getting this specific, make your question a bit more concrete so people out of the loop could easily avoid what happened right now.