Skip to content

Commit 3730128

Browse files
authored
Simplify WIN_CreateHCursor (#12933)
1 parent 6a0505c commit 3730128

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

src/video/windows/SDL_windowsmouse.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,39 +205,30 @@ static HBITMAP CreateMaskBitmap(SDL_Surface *surface, bool is_monochrome)
205205

206206
static HCURSOR WIN_CreateHCursor(SDL_Surface *surface, int hot_x, int hot_y)
207207
{
208-
HCURSOR hcursor;
209-
ICONINFO ii;
208+
HCURSOR hcursor = NULL;
210209
bool is_monochrome = IsMonochromeSurface(surface);
211-
212-
SDL_zero(ii);
213-
ii.fIcon = FALSE;
214-
ii.xHotspot = (DWORD)hot_x;
215-
ii.yHotspot = (DWORD)hot_y;
216-
ii.hbmMask = CreateMaskBitmap(surface, is_monochrome);
217-
ii.hbmColor = is_monochrome ? NULL : CreateColorBitmap(surface);
210+
ICONINFO ii = {
211+
.fIcon = FALSE,
212+
.xHotspot = (DWORD)hot_x,
213+
.yHotspot = (DWORD)hot_y,
214+
.hbmMask = CreateMaskBitmap(surface, is_monochrome),
215+
.hbmColor = is_monochrome ? NULL : CreateColorBitmap(surface)
216+
};
218217

219218
if (!ii.hbmMask || (!is_monochrome && !ii.hbmColor)) {
220219
SDL_SetError("Couldn't create cursor bitmaps");
221-
if (ii.hbmMask) {
222-
DeleteObject(ii.hbmMask);
223-
}
224-
if (ii.hbmColor) {
225-
DeleteObject(ii.hbmColor);
226-
}
227-
return NULL;
220+
goto cleanup;
228221
}
229222

230223
hcursor = CreateIconIndirect(&ii);
231224
if (!hcursor) {
232-
WIN_SetError("CreateIconIndirect()");
233-
DeleteObject(ii.hbmMask);
234-
if (ii.hbmColor) {
235-
DeleteObject(ii.hbmColor);
236-
}
237-
return NULL;
225+
WIN_SetError("CreateIconIndirect failed");
238226
}
239227

240-
DeleteObject(ii.hbmMask);
228+
cleanup:
229+
if (ii.hbmMask) {
230+
DeleteObject(ii.hbmMask);
231+
}
241232
if (ii.hbmColor) {
242233
DeleteObject(ii.hbmColor);
243234
}

0 commit comments

Comments
 (0)