Improved error handling and fixed a NullPointerException bug when setting a canvas' bitmap to null