mirror of
https://github.com/microsoft/DirectXTex.git
synced 2025-07-09 11:40:14 +02:00
Use no-throw new so out-of-memory returns an HRESULT; minor /analyze fix
This commit is contained in:
parent
6a5470b27f
commit
87880558bb
@ -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
|
// Most cases are known apriori based on feature level, but we use this for robustness to handle the few optional cases
|
||||||
UINT formatSupport = 0;
|
UINT formatSupport = 0;
|
||||||
pDevice->CheckFormatSupport( fmt, &formatSupport );
|
HRESULT hr = pDevice->CheckFormatSupport( fmt, &formatSupport );
|
||||||
|
if ( FAILED(hr) )
|
||||||
|
{
|
||||||
|
formatSupport = 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch ( metadata.dimension )
|
switch ( metadata.dimension )
|
||||||
{
|
{
|
||||||
@ -363,7 +367,7 @@ HRESULT CreateTextureEx( ID3D11Device* pDevice, const Image* srcImages, size_t n
|
|||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
#endif
|
#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 )
|
if ( !initData )
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@ static HRESULT _CopyImage( _In_reads_bytes_(size) const void* pPixels, _In_ size
|
|||||||
|
|
||||||
assert( pixelSize <= 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 ) )
|
if ( !_SetupImageArray( (uint8_t*)pPixels, size, metadata, cpFlags, timages.get(), nimages ) )
|
||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
@ -1355,7 +1355,7 @@ HRESULT LoadFromDDSFile( LPCWSTR szFile, DWORD flags, TexMetadata* metadata, Scr
|
|||||||
std::unique_ptr<uint32_t[]> pal8;
|
std::unique_ptr<uint32_t[]> pal8;
|
||||||
if ( convFlags & CONV_FLAGS_PAL8 )
|
if ( convFlags & CONV_FLAGS_PAL8 )
|
||||||
{
|
{
|
||||||
pal8.reset( new uint32_t[256] );
|
pal8.reset( new (std::nothrow) uint32_t[256] );
|
||||||
if ( !pal8 )
|
if ( !pal8 )
|
||||||
{
|
{
|
||||||
return E_OUTOFMEMORY;
|
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) )
|
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 )
|
if ( !temp )
|
||||||
{
|
{
|
||||||
image.Release();
|
image.Release();
|
||||||
|
@ -289,7 +289,7 @@ HRESULT ScratchImage::Initialize( const TexMetadata& mdata )
|
|||||||
size_t pixelSize, nimages;
|
size_t pixelSize, nimages;
|
||||||
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
|
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
|
||||||
|
|
||||||
_image = new Image[ nimages ];
|
_image = new (std::nothrow) Image[ nimages ];
|
||||||
if ( !_image )
|
if ( !_image )
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ HRESULT ScratchImage::Initialize2D( DXGI_FORMAT fmt, size_t width, size_t height
|
|||||||
size_t pixelSize, nimages;
|
size_t pixelSize, nimages;
|
||||||
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
|
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
|
||||||
|
|
||||||
_image = new Image[ nimages ];
|
_image = new (std::nothrow) Image[ nimages ];
|
||||||
if ( !_image )
|
if ( !_image )
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
@ -397,7 +397,7 @@ HRESULT ScratchImage::Initialize3D( DXGI_FORMAT fmt, size_t width, size_t height
|
|||||||
size_t pixelSize, nimages;
|
size_t pixelSize, nimages;
|
||||||
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
|
_DetermineImageArray( _metadata, CP_FLAGS_NONE, nimages, pixelSize );
|
||||||
|
|
||||||
_image = new Image[ nimages ];
|
_image = new (std::nothrow) Image[ nimages ];
|
||||||
if ( !_image )
|
if ( !_image )
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
|
@ -1167,7 +1167,7 @@ HRESULT LoadFromTGAFile( LPCWSTR szFile, TexMetadata* metadata, ScratchImage& im
|
|||||||
}
|
}
|
||||||
else // RLE || EXPAND || INVERTX || !INVERTY
|
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 )
|
if ( !temp )
|
||||||
{
|
{
|
||||||
image.Release();
|
image.Release();
|
||||||
@ -1342,7 +1342,7 @@ HRESULT SaveToTGAFile( const Image& image, LPCWSTR szFile )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Otherwise, write the image one scanline at a time...
|
// 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 )
|
if ( !temp )
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user