Use no-throw new so out-of-memory returns an HRESULT; minor /analyze fix

This commit is contained in:
walbourn_cp 2013-03-20 14:12:40 -07:00
parent 6a5470b27f
commit 87880558bb
4 changed files with 14 additions and 10 deletions

View File

@ -202,7 +202,11 @@ bool IsSupportedTexture( ID3D11Device* pDevice, const TexMetadata& metadata )
// Most cases are known apriori based on feature level, but we use this for robustness to handle the few optional cases
UINT formatSupport = 0;
pDevice->CheckFormatSupport( fmt, &formatSupport );
HRESULT hr = pDevice->CheckFormatSupport( fmt, &formatSupport );
if ( FAILED(hr) )
{
formatSupport = 0;
}
switch ( metadata.dimension )
{
@ -363,7 +367,7 @@ HRESULT CreateTextureEx( ID3D11Device* pDevice, const Image* srcImages, size_t n
return E_INVALIDARG;
#endif
std::unique_ptr<D3D11_SUBRESOURCE_DATA[]> initData( new D3D11_SUBRESOURCE_DATA[ metadata.mipLevels * metadata.arraySize ] );
std::unique_ptr<D3D11_SUBRESOURCE_DATA[]> initData( new (std::nothrow) D3D11_SUBRESOURCE_DATA[ metadata.mipLevels * metadata.arraySize ] );
if ( !initData )
return E_OUTOFMEMORY;

View File

@ -911,7 +911,7 @@ static HRESULT _CopyImage( _In_reads_bytes_(size) const void* pPixels, _In_ size
assert( pixelSize <= size );
std::unique_ptr<Image[]> timages( new Image[nimages] );
std::unique_ptr<Image[]> timages( new (std::nothrow) Image[nimages] );
if ( !_SetupImageArray( (uint8_t*)pPixels, size, metadata, cpFlags, timages.get(), nimages ) )
{
return E_FAIL;
@ -1355,7 +1355,7 @@ HRESULT LoadFromDDSFile( LPCWSTR szFile, DWORD flags, TexMetadata* metadata, Scr
std::unique_ptr<uint32_t[]> pal8;
if ( convFlags & CONV_FLAGS_PAL8 )
{
pal8.reset( new uint32_t[256] );
pal8.reset( new (std::nothrow) uint32_t[256] );
if ( !pal8 )
{
return E_OUTOFMEMORY;
@ -1384,7 +1384,7 @@ HRESULT LoadFromDDSFile( LPCWSTR szFile, DWORD flags, TexMetadata* metadata, Scr
if ( (convFlags & CONV_FLAGS_EXPAND) || (flags & DDS_FLAGS_LEGACY_DWORD) )
{
std::unique_ptr<uint8_t[]> temp( new uint8_t[ remaining ] );
std::unique_ptr<uint8_t[]> temp( new (std::nothrow) uint8_t[ remaining ] );
if ( !temp )
{
image.Release();

View File

@ -289,7 +289,7 @@ HRESULT ScratchImage::Initialize( const TexMetadata& mdata )
size_t pixelSize, nimages;
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
_image = new Image[ nimages ];
_image = new (std::nothrow) Image[ nimages ];
if ( !_image )
return E_OUTOFMEMORY;
@ -351,7 +351,7 @@ HRESULT ScratchImage::Initialize2D( DXGI_FORMAT fmt, size_t width, size_t height
size_t pixelSize, nimages;
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
_image = new Image[ nimages ];
_image = new (std::nothrow) Image[ nimages ];
if ( !_image )
return E_OUTOFMEMORY;
@ -397,7 +397,7 @@ HRESULT ScratchImage::Initialize3D( DXGI_FORMAT fmt, size_t width, size_t height
size_t pixelSize, nimages;
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
_image = new Image[ nimages ];
_image = new (std::nothrow) Image[ nimages ];
if ( !_image )
{
Release();

View File

@ -1167,7 +1167,7 @@ HRESULT LoadFromTGAFile( LPCWSTR szFile, TexMetadata* metadata, ScratchImage& im
}
else // RLE || EXPAND || INVERTX || !INVERTY
{
std::unique_ptr<uint8_t[]> temp( new uint8_t[ remaining ] );
std::unique_ptr<uint8_t[]> temp( new (std::nothrow) uint8_t[ remaining ] );
if ( !temp )
{
image.Release();
@ -1342,7 +1342,7 @@ HRESULT SaveToTGAFile( const Image& image, LPCWSTR szFile )
else
{
// Otherwise, write the image one scanline at a time...
std::unique_ptr<uint8_t[]> temp( new uint8_t[ rowPitch ] );
std::unique_ptr<uint8_t[]> temp( new (std::nothrow) uint8_t[ rowPitch ] );
if ( !temp )
return E_OUTOFMEMORY;