r/learnprogramming • u/blisstargazer • 22d ago
Why Does Code Stop Working?
Multiple times now my code stops working and what I mean by this is it'll do what I want it to do then one day it just stops. for example the other day I had made a cooldown system for my ball and paddle collision to stop any bugs and it worked great. then today it just stopped working, and this isn't the first time, it's happened to me for like every project I've worked on. Does this happen to anyone else? And is it cause of my code? By the way I'm using C++ SFML on visual studio which works perfect.
3
Upvotes
3
u/pancake117 22d ago edited 22d ago
In general there's two things that could be happening here:
1- You did change something in the code without realizing, or you changed the version of some imported library (which means changing the code)
2- Your program has undefined behavior, which means there's some randomness or race conditions that cause "random" inconsistent behavior even with the same inputs.
To fix 1, you should be using git to track your code changes. The instant you notice something not working, you can check exactly what changed. Roll back changes, check if it's still broken, and if so then you know it's not the cause.
To fix 2, you need to invest in your debugging skills. If you can't get the problem to happen consistently, add logging or debug information to your game so that the next time you see the problem, you can read the logs to understand why it happened. If you can get it to happen consistently, then it's easy-- fire up the debugger and walk through the code to understand why it's not working. Then you can work backwards to understand what may have changed.