Added error checking to check if cairo render state is valid.