Have to reset driver every time the code crashes

I have a jetson nano with an IMX477 camera module. It works perfectly after configuring with sudo /opt/nvidia/jetson-io/jetson-io.py and runs my code. I am then using C++ and OpenCV to write some code. The issue is that whenever I run my code and something goes wrong (i.e. I get the Aborted (core dumped) warning) I have to rerun the jetson-io.py script, forcing a restart. If I don’t, the camera only reads back empty frames until I reset as mentioned above. Is there a way around this, for example some way of resetting the camera at the beginning of the function or do I just have to reset until I get the function running reliably.

Please try the command below when your code crushes:

sudo systemctl restart nvargus-daemon.service