re-use return value of SDL_SetError/WIN_SetErrorFromHRESULT/SDL_OutOfMemory

This commit is contained in:
pionere
2022-01-17 17:22:30 +01:00
committed by Ryan C. Gordon
parent ebdd536676
commit 60deadba59
18 changed files with 52 additions and 102 deletions

View File

@@ -584,8 +584,7 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
if (!texturedata) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) {
@@ -621,8 +620,7 @@ D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
if (!texturedata) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
@@ -647,8 +645,7 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
IDirect3DDevice9 *device = data->device;
if (!texturedata) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
texturedata->locked_rect = *rect;
@@ -756,8 +753,7 @@ D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
texturedata = (D3D_TextureData *)texture->driverdata;
if (!texturedata) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
/* Make sure the render target is updated if it was locked and written to */
@@ -942,8 +938,7 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH
SDL_assert(*shader == NULL);
if (!texturedata) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
UpdateTextureScaleMode(data, texturedata, 0);

View File

@@ -1114,8 +1114,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
}
if (texture->format == SDL_PIXELFORMAT_YV12 ||
@@ -1132,8 +1131,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
}
result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
@@ -1143,8 +1141,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
}
}
@@ -1165,8 +1162,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
}
}
@@ -1181,8 +1177,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
}
if (textureData->yuv) {
@@ -1193,8 +1188,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
}
result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
(ID3D11Resource *)textureData->mainTextureV,
@@ -1203,8 +1197,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
}
}
@@ -1220,8 +1213,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
}
}
@@ -1237,8 +1229,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
&textureData->mainTextureRenderTargetView);
if (FAILED(result)) {
D3D11_DestroyTexture(renderer, texture);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRenderTargetView"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRenderTargetView"), result);
}
}
@@ -1295,8 +1286,7 @@ D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *tex
NULL,
&stagingTexture);
if (FAILED(result)) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
}
/* Get a write-only pointer to data in the staging texture: */
@@ -1308,9 +1298,8 @@ D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *tex
&textureMemory
);
if (FAILED(result)) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
SAFE_RELEASE(stagingTexture);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
}
src = (const Uint8 *)pixels;
@@ -1362,8 +1351,7 @@ D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
if (!textureData) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch) < 0) {
@@ -1408,8 +1396,7 @@ D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
if (!textureData) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
@@ -1434,8 +1421,7 @@ D3D11_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture,
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
if (!textureData) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
@@ -1460,8 +1446,7 @@ D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
D3D11_MAPPED_SUBRESOURCE textureMemory;
if (!textureData) {
SDL_SetError("Texture is not currently available");
return -1;
return SDL_SetError("Texture is not currently available");
}
if (textureData->yuv || textureData->nv12) {
@@ -1505,8 +1490,7 @@ D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
NULL,
&textureData->stagingTexture);
if (FAILED(result)) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
}
/* Get a write-only pointer to data in the staging texture: */
@@ -1518,9 +1502,8 @@ D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
&textureMemory
);
if (FAILED(result)) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
SAFE_RELEASE(textureData->stagingTexture);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
}
/* Make note of where the staging texture will be written to
@@ -1718,8 +1701,7 @@ D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
&mappedResource
);
if (FAILED(result)) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [vertex buffer]"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [vertex buffer]"), result);
}
SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes);
ID3D11DeviceContext_Unmap(rendererData->d3dContext, (ID3D11Resource *)rendererData->vertexBuffers[vbidx], 0);
@@ -1746,8 +1728,7 @@ D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
&rendererData->vertexBuffers[vbidx]
);
if (FAILED(result)) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex buffer]"), result);
return -1;
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex buffer]"), result);
}
rendererData->vertexBufferSizes[vbidx] = dataSizeInBytes;

View File

@@ -442,8 +442,8 @@ TextureSpillLRU(PSP_RenderData* data, size_t wanted) {
}
LRUTargetRemove(data, lru);
} else {
SDL_SetError("Could not spill more VRAM to system memory. VRAM : %dKB,(%dKB), wanted %dKB", vmemavail()/1024, vlargestblock()/1024, wanted/1024);
return -1; //Asked to spill but there nothing to spill
// Asked to spill but there nothing to spill
return SDL_SetError("Could not spill more VRAM to system memory. VRAM : %dKB,(%dKB), wanted %dKB", vmemavail()/1024, vlargestblock()/1024, wanted/1024);
}
return 0;
}

View File

@@ -99,8 +99,7 @@ SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
return 0;
}
SDL_SetError("Software renderer doesn't have an output surface");
return -1;
return SDL_SetError("Software renderer doesn't have an output surface");
}
static int