Fix unlinking nullptr error scopes if device init failed

When device initialization failed, DeviceBase::mCurrentErrorScope is
nullptr so we need to guard the call to UnlinkForShutdown.

Bug: chromium:1081998
Change-Id: I65a1948117fa9461f7fc8d2d1d70aef669bc375d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/21685
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp
index db4936a..b3f4766 100644
--- a/src/dawn_native/Device.cpp
+++ b/src/dawn_native/Device.cpp
@@ -154,8 +154,11 @@
         // At this point GPU operations are always finished, so we are in the disconnected state.
         mState = State::Disconnected;
 
+        // mCurrentErrorScope can be null if we failed device initialization.
+        if (mCurrentErrorScope.Get() != nullptr) {
+            mCurrentErrorScope->UnlinkForShutdown();
+        }
         mErrorScopeTracker = nullptr;
-        mCurrentErrorScope->UnlinkForShutdown();
         mFenceSignalTracker = nullptr;
         mDynamicUploader = nullptr;
         mMapRequestTracker = nullptr;