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

@ -153,8 +153,7 @@ SDL_InitSubSystem(Uint32 flags)
Uint32 flags_initialized = 0;
if (!SDL_MainIsReady) {
SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
return -1;
return SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
}
/* Clear the error message */

View file

@ -1523,8 +1523,7 @@ SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)
/* SDL_OpenAudio() is legacy and can only act on Device ID #1. */
if (open_devices[0] != NULL) {
SDL_SetError("Audio device is already opened");
return -1;
return SDL_SetError("Audio device is already opened");
}
if (obtained) {

View file

@ -1135,8 +1135,7 @@ COREAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
this->hidden->ready_semaphore = NULL;
if ((this->hidden->thread != NULL) && (this->hidden->thread_error != NULL)) {
SDL_SetError("%s", this->hidden->thread_error);
return -1;
return SDL_SetError("%s", this->hidden->thread_error);
}
return (this->hidden->thread != NULL) ? 0 : -1;

View file

@ -492,8 +492,7 @@ SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
++index;
}
SDL_SetError("Couldn't find joystick in haptic device list");
return -1;
return SDL_SetError("Couldn't find joystick in haptic device list");
}
void
@ -959,8 +958,7 @@ SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SD
REFGUID type = SDL_SYS_HapticEffectType(base);
if (type == NULL) {
SDL_SetError("Haptic: Unknown effect type.");
return -1;
return SDL_SetError("Haptic: Unknown effect type.");
}
/* Get the effect. */

View file

@ -246,8 +246,7 @@ SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
++index;
}
SDL_SetError("Couldn't find joystick in haptic device list");
return -1;
return SDL_SetError("Couldn't find joystick in haptic device list");
}
void

View file

@ -454,8 +454,7 @@ HIDAPI_DriverGameCube_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *jo
}
/* Should never get here! */
SDL_SetError("Couldn't find joystick");
return -1;
return SDL_SetError("Couldn't find joystick");
}
static int

View file

@ -1023,8 +1023,7 @@ HIDAPI_DriverSwitch_ActuallyRumbleJoystick(SDL_DriverSwitch_Context *ctx, Uint16
ctx->m_bRumbleActive = (low_frequency_rumble || high_frequency_rumble) ? SDL_TRUE : SDL_FALSE;
if (!WriteRumble(ctx)) {
SDL_SetError("Couldn't send rumble packet");
return -1;
return SDL_SetError("Couldn't send rumble packet");
}
return 0;
}

View file

@ -309,8 +309,7 @@ HIDAPI_JoystickInit(void)
#endif
if (SDL_hid_init() < 0) {
SDL_SetError("Couldn't initialize hidapi");
return -1;
return SDL_SetError("Couldn't initialize hidapi");
}
for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
@ -871,8 +870,7 @@ HIDAPI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint1
result = device->driver->RumbleJoystick(device, joystick, low_frequency_rumble, high_frequency_rumble);
} else {
SDL_SetError("Rumble failed, device disconnected");
result = -1;
result = SDL_SetError("Rumble failed, device disconnected");
}
return result;
@ -888,8 +886,7 @@ HIDAPI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16
result = device->driver->RumbleJoystickTriggers(device, joystick, left_rumble, right_rumble);
} else {
SDL_SetError("Rumble failed, device disconnected");
result = -1;
result = SDL_SetError("Rumble failed, device disconnected");
}
return result;
@ -919,8 +916,7 @@ HIDAPI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue
result = device->driver->SetJoystickLED(device, joystick, red, green, blue);
} else {
SDL_SetError("SetLED failed, device disconnected");
result = -1;
result = SDL_SetError("SetLED failed, device disconnected");
}
return result;
@ -936,8 +932,7 @@ HIDAPI_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
result = device->driver->SendJoystickEffect(device, joystick, data, size);
} else {
SDL_SetError("SendEffect failed, device disconnected");
result = -1;
result = SDL_SetError("SendEffect failed, device disconnected");
}
return result;
@ -953,8 +948,7 @@ HIDAPI_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
result = device->driver->SetJoystickSensorsEnabled(device, joystick, enabled);
} else {
SDL_SetError("SetSensorsEnabled failed, device disconnected");
result = -1;
result = SDL_SetError("SetSensorsEnabled failed, device disconnected");
}
return result;

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

View file

@ -52,11 +52,9 @@ SDL_SYS_CreateThread(SDL_Thread * thread)
thread->handle = (void *) new std::thread(std::move(cpp_thread));
return 0;
} catch (std::system_error & ex) {
SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
return -1;
return SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
} catch (std::bad_alloc &) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
}

View file

@ -1404,8 +1404,7 @@ int SDL_ConvertPixels(int width, int height,
}
#else
if (SDL_ISPIXELFORMAT_FOURCC(src_format) || SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
SDL_SetError("SDL not built with YUV support");
return -1;
return SDL_SetError("SDL not built with YUV support");
}
#endif

View file

@ -1879,18 +1879,15 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
}
if ((flags & SDL_WINDOW_VULKAN) && (flags & SDL_WINDOW_OPENGL)) {
SDL_SetError("Vulkan and OpenGL not supported on same window");
return -1;
return SDL_SetError("Vulkan and OpenGL not supported on same window");
}
if ((flags & SDL_WINDOW_METAL) && (flags & SDL_WINDOW_OPENGL)) {
SDL_SetError("Metal and OpenGL not supported on same window");
return -1;
return SDL_SetError("Metal and OpenGL not supported on same window");
}
if ((flags & SDL_WINDOW_METAL) && (flags & SDL_WINDOW_VULKAN)) {
SDL_SetError("Metal and Vulkan not supported on same window");
return -1;
return SDL_SetError("Metal and Vulkan not supported on same window");
}
if (need_gl_unload) {

View file

@ -35,8 +35,7 @@ NACL_CreateWindow(_THIS, SDL_Window * window)
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
if (driverdata->window) {
SDL_SetError("NaCl only supports one window");
return -1;
return SDL_SetError("NaCl only supports one window");
}
driverdata->window = window;

View file

@ -259,8 +259,7 @@ VITA_CreateWindow(_THIS, SDL_Window * window)
// Vita can only have one window
if (Vita_Window != NULL)
{
SDL_SetError("Only one window supported");
return -1;
return SDL_SetError("Only one window supported");
}
Vita_Window = window;

View file

@ -478,8 +478,7 @@ WINRT_InitModes(_THIS)
hr = CreateDXGIFactory1(SDL_IID_IDXGIFactory2, (void **)&dxgiFactory2);
if (FAILED(hr)) {
WIN_SetErrorFromHRESULT(__FUNCTION__ ", CreateDXGIFactory1() failed", hr);
return -1;
return WIN_SetErrorFromHRESULT(__FUNCTION__ ", CreateDXGIFactory1() failed", hr);
}
for (int adapterIndex = 0; ; ++adapterIndex) {
@ -630,14 +629,12 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
// Make sure that only one window gets created, at least until multimonitor
// support is added.
if (WINRT_GlobalSDLWindow != NULL) {
SDL_SetError("WinRT only supports one window");
return -1;
return SDL_SetError("WinRT only supports one window");
}
SDL_WindowData *data = new SDL_WindowData; /* use 'new' here as SDL_WindowData may use WinRT/C++ types */
if (!data) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
window->driverdata = data;
data->sdlWindow = window;