Fix possible crash when opening inventory