Bug 1386487 - Add checking mechanism if ID3D11Buffer created fail. r=rhunt, dvander
authorvincentliu <vliu@mozilla.com>
Wed, 09 Aug 2017 23:23:18 +0800
changeset 643337 f216d5050f0017f59c658b7ee61a461682b65c10
parent 643336 0d348109f6002fa3f01f2a75139c77cf246fa4bf
child 643338 b53d1d68db0e773d7a032225946bcce66a1d40b8
push id73068
push usergpascutto@mozilla.com
push dateWed, 09 Aug 2017 16:52:24 +0000
reviewersrhunt, dvander
bugs1386487
milestone57.0a1
Bug 1386487 - Add checking mechanism if ID3D11Buffer created fail. r=rhunt, dvander
gfx/layers/d3d11/MLGDeviceD3D11.cpp
--- a/gfx/layers/d3d11/MLGDeviceD3D11.cpp
+++ b/gfx/layers/d3d11/MLGDeviceD3D11.cpp
@@ -620,17 +620,21 @@ MLGBufferD3D11::Create(ID3D11Device* aDe
   }
 
   D3D11_SUBRESOURCE_DATA data;
   data.pSysMem = aInitialData;
   data.SysMemPitch = aSize;
   data.SysMemSlicePitch = 0;
 
   RefPtr<ID3D11Buffer> buffer;
-  aDevice->CreateBuffer(&desc, aInitialData ? &data : nullptr, getter_AddRefs(buffer));
+  HRESULT hr = aDevice->CreateBuffer(&desc, aInitialData ? &data : nullptr, getter_AddRefs(buffer));
+  if (FAILED(hr) || !buffer) {
+    gfxCriticalError() << "Failed to create ID3D11Buffer.";
+    return nullptr;
+  }
 
   return new MLGBufferD3D11(buffer, aType, aSize);
 }
 
 MLGBufferD3D11::MLGBufferD3D11(ID3D11Buffer* aBuffer, MLGBufferType aType, size_t aSize)
  : mBuffer(aBuffer),
    mType(aType),
    mSize(aSize)
@@ -1332,16 +1336,17 @@ ToD3D11Map(MLGMapType aType)
   }
   return D3D11_MAP_WRITE;
 }
 
 bool
 MLGDeviceD3D11::Map(MLGResource* aResource, MLGMapType aType, MLGMappedResource* aMap)
 {
   ID3D11Resource* resource = aResource->AsResourceD3D11()->GetResource();
+  MOZ_ASSERT(resource);
 
   D3D11_MAPPED_SUBRESOURCE map;
   HRESULT hr = mCtx->Map(resource, 0, ToD3D11Map(aType), 0, &map);
 
   if (FAILED(hr)) {
     gfxWarning() << "Could not map MLG resource: " << hexa(hr);
     return false;
   }