Added more defensive code to prevent the camera library from crashing.