when the curve cache is enabled. There was a chance it could dereference NULL. Added some error checks to fix it.