From 6bda63934dc6590d8d7462fe96f678bfd6a2d6cc Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 14 Apr 2013 18:05:14 -0400 Subject: [PATCH 01/18] Make the new SDL_RWops::hidden::unknown::data2 field a void*, not an int. --- include/SDL_rwops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL_rwops.h b/include/SDL_rwops.h index acc499ffb..3ad1ae4b8 100644 --- a/include/SDL_rwops.h +++ b/include/SDL_rwops.h @@ -138,7 +138,7 @@ typedef struct SDL_RWops struct { void *data1; - int data2; + void *data2; } unknown; } hidden; From 86b8376c2b6112d1a27b14895b24b81dc5cc4449 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 15 Apr 2013 22:49:23 -0400 Subject: [PATCH 02/18] Fixed a compiler warning on Visual Studio. --- test/testautomation_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 1c0dac6c2..ccaa2ed8a 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -1522,7 +1522,7 @@ video_getSetWindowData(void *arg) returnValue = TEST_ABORTED; goto cleanup; } - userdata = (char *)strdup(referenceUserdata); + userdata = SDL_strdup(referenceUserdata); if (userdata == NULL) { returnValue = TEST_ABORTED; goto cleanup; From 19909e7dcbb676825d854080b178d24cab01ffe3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 16 Apr 2013 00:09:48 -0400 Subject: [PATCH 03/18] Maybe actually fix compiler warning this time. --- test/testautomation_video.c | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testautomation_video.c b/test/testautomation_video.c index ccaa2ed8a..4e2cfa593 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -3,6 +3,7 @@ */ #include +#include /* Visual Studio 2008 doesn't have stdint.h */ #if defined(_MSC_VER) && _MSC_VER <= 1500 From 969adca54c18b05d79037a7852b0f4240059ccec Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 16 Apr 2013 01:05:32 -0400 Subject: [PATCH 04/18] Removed C++-style single-line comments from a public header (thanks, Martin!). Fixes Bugzilla #1803. --- include/SDL_mouse.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/SDL_mouse.h b/include/SDL_mouse.h index f6d6300cb..1cfe09260 100644 --- a/include/SDL_mouse.h +++ b/include/SDL_mouse.h @@ -47,18 +47,18 @@ typedef struct SDL_Cursor SDL_Cursor; /* Implementation dependent */ */ typedef enum { - SDL_SYSTEM_CURSOR_ARROW, // Arrow - SDL_SYSTEM_CURSOR_IBEAM, // I-beam - SDL_SYSTEM_CURSOR_WAIT, // Wait - SDL_SYSTEM_CURSOR_CROSSHAIR, // Crosshair - SDL_SYSTEM_CURSOR_WAITARROW, // Small wait cursor (or Wait if not available) - SDL_SYSTEM_CURSOR_SIZENWSE, // Double arrow pointing northwest and southeast - SDL_SYSTEM_CURSOR_SIZENESW, // Double arrow pointing northeast and southwest - SDL_SYSTEM_CURSOR_SIZEWE, // Double arrow pointing west and east - SDL_SYSTEM_CURSOR_SIZENS, // Double arrow pointing north and south - SDL_SYSTEM_CURSOR_SIZEALL, // Four pointed arrow pointing north, south, east, and west - SDL_SYSTEM_CURSOR_NO, // Slashed circle or crossbones - SDL_SYSTEM_CURSOR_HAND, // Hand + SDL_SYSTEM_CURSOR_ARROW, /**< Arrow */ + SDL_SYSTEM_CURSOR_IBEAM, /**< I-beam */ + SDL_SYSTEM_CURSOR_WAIT, /**< Wait */ + SDL_SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair */ + SDL_SYSTEM_CURSOR_WAITARROW, /**< Small wait cursor (or Wait if not available) */ + SDL_SYSTEM_CURSOR_SIZENWSE, /**< Double arrow pointing northwest and southeast */ + SDL_SYSTEM_CURSOR_SIZENESW, /**< Double arrow pointing northeast and southwest */ + SDL_SYSTEM_CURSOR_SIZEWE, /**< Double arrow pointing west and east */ + SDL_SYSTEM_CURSOR_SIZENS, /**< Double arrow pointing north and south */ + SDL_SYSTEM_CURSOR_SIZEALL, /**< Four pointed arrow pointing north, south, east, and west */ + SDL_SYSTEM_CURSOR_NO, /**< Slashed circle or crossbones */ + SDL_SYSTEM_CURSOR_HAND, /**< Hand */ SDL_NUM_SYSTEM_CURSORS } SDL_SystemCursor; From 226fdc16e64a99422d102f5fafe08ad1c9ee25f0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 16 Apr 2013 09:33:33 -0700 Subject: [PATCH 05/18] BMP files don't contain alpha information in the palette, the fourth element is reserved and must be zero. --- src/video/SDL_bmp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index a6341f4c8..5b861dd93 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -260,6 +260,12 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) SDL_RWread(src, &palette->colors[i].g, 1, 1); SDL_RWread(src, &palette->colors[i].r, 1, 1); SDL_RWread(src, &palette->colors[i].a, 1, 1); + + /* According to Microsoft documentation, the fourth element + is reserved and must be zero, so we shouldn't treat it as + alpha. + */ + palette->colors[i].a = SDL_ALPHA_OPAQUE; } } } From eb97bff0bd6946b2fc8363de068d421048285636 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 17 Apr 2013 01:32:06 -0700 Subject: [PATCH 06/18] Fixed bug 1802 - NULL pointer dereference in SDL_AllocRW() if out of memory. Philipp Wiesemann There is a NULL pointer dereference in SDL_AllocRW() if the system is out of memory. The "type" field is always written. This may be fixed with an early return. Or an else{} or not writing the field and using slower SDL_calloc(). This fault was recently introduced (http://hg.libsdl.org/SDL/rev/681820ca0e78). --- src/file/SDL_rwops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index ec4f5be8f..44b0e8407 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -628,8 +628,9 @@ SDL_AllocRW(void) area = (SDL_RWops *) SDL_malloc(sizeof *area); if (area == NULL) { SDL_OutOfMemory(); + } else { + area->type = SDL_RWOPS_UNKNOWN; } - area->type = SDL_RWOPS_UNKNOWN; return (area); } From a438cbd7fe5de633b39170135ed5d613b18e1ef2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 17 Apr 2013 01:35:10 -0700 Subject: [PATCH 07/18] Fixed bug 1804 - Memory leak issue in src/video/x11/SDL_x11mouse.c Nitz In SDL_x11mouse.c file there is function named static Cursor X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y) { // Some code data_bits = SDL_calloc(1, surface->h * width_bytes); mask_bits = SDL_calloc(1, surface->h * width_bytes); if (!data_bits || !mask_bits) { SDL_OutOfMemory(); return None; } // Some code } Here is the problem in if statement, suppose if !data_bits is false and !mask_bits is true then, data_bits will go out of scope and leaks the memory it points to. Solution is that data_bits and mask_bits should be checked separately, not by using OR operator. --- src/video/x11/SDL_x11mouse.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c index 52e1cce2a..1d021b7b6 100644 --- a/src/video/x11/SDL_x11mouse.c +++ b/src/video/x11/SDL_x11mouse.c @@ -129,8 +129,14 @@ X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y) unsigned int width_bytes = ((surface->w + 7) & ~7) / 8; data_bits = SDL_calloc(1, surface->h * width_bytes); + if (!data_bits) { + SDL_OutOfMemory(); + return None; + } + mask_bits = SDL_calloc(1, surface->h * width_bytes); - if (!data_bits || !mask_bits) { + if (!mask_bits) { + SDL_free(data_bits); SDL_OutOfMemory(); return None; } From 090d061ff264d76568d04966fda59bd5416a4d04 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 17 Apr 2013 01:38:59 -0700 Subject: [PATCH 08/18] Fixed bug 1805 - Memory Leak issue in src/video/x11/edid-parse.c file Nitz In Function, MonitorInfo * decode_edid (const uchar *edid) In this function "info" is going out of scope and leaks the storage it points to, if the first if condition get true: if (!decode_header (edid)) return NULL; So while returning from this if statement there should be free for "info" pointer. --- src/video/x11/edid-parse.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/video/x11/edid-parse.c b/src/video/x11/edid-parse.c index 67e17e167..8608bf254 100644 --- a/src/video/x11/edid-parse.c +++ b/src/video/x11/edid-parse.c @@ -524,29 +524,17 @@ decode_edid (const uchar *edid) decode_check_sum (edid, info); - if (!decode_header (edid)) - return NULL; - - if (!decode_vendor_and_product_identification (edid, info)) - return NULL; - - if (!decode_edid_version (edid, info)) - return NULL; - - if (!decode_display_parameters (edid, info)) - return NULL; - - if (!decode_color_characteristics (edid, info)) - return NULL; - - if (!decode_established_timings (edid, info)) - return NULL; - - if (!decode_standard_timings (edid, info)) - return NULL; - - if (!decode_descriptors (edid, info)) + if (!decode_header (edid) || + !decode_vendor_and_product_identification (edid, info) || + !decode_edid_version (edid, info) || + !decode_display_parameters (edid, info) || + !decode_color_characteristics (edid, info) || + !decode_established_timings (edid, info) || + !decode_standard_timings (edid, info) || + !decode_descriptors (edid, info)) { + free(info); return NULL; + } return info; } From 5bd319e5b5fce627da322de24ac33b9c1cab3d55 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Wed, 17 Apr 2013 07:35:30 -0700 Subject: [PATCH 09/18] Fix bug 1764: incorrect variable assignment in RenderDrawLinesWithRects --- src/render/SDL_render.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index cab98d420..be76a88eb 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -1297,10 +1297,10 @@ RenderDrawLinesWithRects(SDL_Renderer * renderer, frect->h = renderer->scale.y; } else { /* FIXME: We can't use a rect for this line... */ - frects[0].x = points[i].x * renderer->scale.x; - frects[0].y = points[i].y * renderer->scale.y; - frects[1].x = points[i+1].x * renderer->scale.x; - frects[1].y = points[i+1].y * renderer->scale.y; + fpoints[0].x = points[i].x * renderer->scale.x; + fpoints[0].y = points[i].y * renderer->scale.y; + fpoints[1].x = points[i+1].x * renderer->scale.x; + fpoints[1].y = points[i+1].y * renderer->scale.y; status += renderer->RenderDrawLines(renderer, fpoints, 2); } } From 56c27c7be94fbbefc72340da5d40b3a20fafb84f Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Wed, 17 Apr 2013 08:09:11 -0700 Subject: [PATCH 10/18] Fix bug 1789: SDL_IntersectRect intersection with empty rect does not set result to empty; add test coverage to Rect suite --- src/video/SDL_rect.c | 86 +++++++++++++++++++++++++++++++------- test/testautomation_rect.c | 17 +++++++- 2 files changed, 87 insertions(+), 16 deletions(-) diff --git a/src/video/SDL_rect.c b/src/video/SDL_rect.c index 23894dc3d..045d3f1cf 100644 --- a/src/video/SDL_rect.c +++ b/src/video/SDL_rect.c @@ -29,8 +29,13 @@ SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B) { int Amin, Amax, Bmin, Bmax; - if (!A || !B) { - // TODO error message + if (!A) { + SDL_InvalidParamError("A"); + return SDL_FALSE; + } + + if (!B) { + SDL_InvalidParamError("B"); return SDL_FALSE; } @@ -71,13 +76,25 @@ SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) { int Amin, Amax, Bmin, Bmax; - if (!A || !B || !result) { - // TODO error message + if (!A) { + SDL_InvalidParamError("A"); + return SDL_FALSE; + } + + if (!B) { + SDL_InvalidParamError("B"); + return SDL_FALSE; + } + + if (!result) { + SDL_InvalidParamError("result"); return SDL_FALSE; } /* Special cases for empty rects */ if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) { + result->w = 0; + result->h = 0; return SDL_FALSE; } @@ -113,7 +130,18 @@ SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) { int Amin, Amax, Bmin, Bmax; - if (!A || !B || !result) { + if (!A) { + SDL_InvalidParamError("A"); + return; + } + + if (!B) { + SDL_InvalidParamError("B"); + return; + } + + if (!result) { + SDL_InvalidParamError("result"); return; } @@ -171,12 +199,12 @@ SDL_EnclosePoints(const SDL_Point * points, int count, const SDL_Rect * clip, int x, y, i; if (!points) { - /* TODO error message */ + SDL_InvalidParamError("points"); return SDL_FALSE; } if (count < 1) { - /* TODO error message */ + SDL_InvalidParamError("count"); return SDL_FALSE; } @@ -298,8 +326,28 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, int recty2; int outcode1, outcode2; - if (!rect || !X1 || !Y1 || !X2 || !Y2) { - // TODO error message + if (!rect) { + SDL_InvalidParamError("rect"); + return SDL_FALSE; + } + + if (!X1) { + SDL_InvalidParamError("X1"); + return SDL_FALSE; + } + + if (!Y1) { + SDL_InvalidParamError("Y1"); + return SDL_FALSE; + } + + if (!X2) { + SDL_InvalidParamError("X2"); + return SDL_FALSE; + } + + if (!Y2) { + SDL_InvalidParamError("Y2"); return SDL_FALSE; } @@ -418,18 +466,28 @@ SDL_GetSpanEnclosingRect(int width, int height, int span_y1, span_y2; int rect_y1, rect_y2; - if (width < 1 || height < 1) { - // TODO error message + if (width < 1) { + SDL_InvalidParamError("width"); return SDL_FALSE; } - if (!rects || !span) { - // TODO error message + if (height < 1) { + SDL_InvalidParamError("height"); + return SDL_FALSE; + } + + if (!rects) { + SDL_InvalidParamError("rects"); + return SDL_FALSE; + } + + if (!span) { + SDL_InvalidParamError("span"); return SDL_FALSE; } if (numrects < 1) { - // TODO error message + SDL_InvalidParamError("numrects"); return SDL_FALSE; } diff --git a/test/testautomation_rect.c b/test/testautomation_rect.c index 98ac8424f..333c973ed 100644 --- a/test/testautomation_rect.c +++ b/test/testautomation_rect.c @@ -614,8 +614,11 @@ int rect_testIntersectRectEmpty (void *arg) SDL_Rect rectB; SDL_Rect result; SDL_bool intersection; + SDL_bool empty; // Rect A empty + result.w = SDLTest_RandomIntegerInRange(1, 100); + result.h = SDLTest_RandomIntegerInRange(1, 100); refRectA.x = SDLTest_RandomIntegerInRange(1, 100); refRectA.y = SDLTest_RandomIntegerInRange(1, 100); refRectA.w = SDLTest_RandomIntegerInRange(1, 100); @@ -627,8 +630,12 @@ int rect_testIntersectRectEmpty (void *arg) rectB = refRectB; intersection = SDL_IntersectRect(&rectA, &rectB, &result); _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL); - + empty = (SDL_bool)SDL_RectEmpty(&result); + SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE"); + // Rect B empty + result.w = SDLTest_RandomIntegerInRange(1, 100); + result.h = SDLTest_RandomIntegerInRange(1, 100); refRectA.x = SDLTest_RandomIntegerInRange(1, 100); refRectA.y = SDLTest_RandomIntegerInRange(1, 100); refRectA.w = SDLTest_RandomIntegerInRange(1, 100); @@ -640,8 +647,12 @@ int rect_testIntersectRectEmpty (void *arg) rectB = refRectB; intersection = SDL_IntersectRect(&rectA, &rectB, &result); _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL); + empty = (SDL_bool)SDL_RectEmpty(&result); + SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE"); // Rect A and B empty + result.w = SDLTest_RandomIntegerInRange(1, 100); + result.h = SDLTest_RandomIntegerInRange(1, 100); refRectA.x = SDLTest_RandomIntegerInRange(1, 100); refRectA.y = SDLTest_RandomIntegerInRange(1, 100); refRectA.w = SDLTest_RandomIntegerInRange(1, 100); @@ -655,8 +666,10 @@ int rect_testIntersectRectEmpty (void *arg) rectB = refRectB; intersection = SDL_IntersectRect(&rectA, &rectB, &result); _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL); + empty = (SDL_bool)SDL_RectEmpty(&result); + SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE"); - return TEST_COMPLETED; + return TEST_COMPLETED; } /*! From 71b29b3822ea7caf40ce3710b96bb03ff4d99a78 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 17 Apr 2013 11:45:50 -0400 Subject: [PATCH 11/18] Don't use glDisable(GL_TEXTURE_2D) in GLES2 renderer. Fixes Bugzilla #1799. --HG-- extra : rebase_source : bdcc78e0cbdb2879c7ae24666bea567ce24dcd74 --- src/render/opengles2/SDL_render_gles2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 2877ef63f..0d6fe5d0e 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -1564,8 +1564,7 @@ static int GLES2_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) { GLES2_TextureData *texturedata = (GLES2_TextureData *)texture->driverdata; GLES2_ActivateRenderer(renderer); - data->glActiveTexture(GL_TEXTURE0); - data->glDisable(texturedata->texture_type); + data->glBindTexture(texturedata->texture_type, 0); return 0; } From 8069b5a7f365ae1af4c0c76d1e81fc48610ca14b Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 16 Apr 2013 01:38:08 -0400 Subject: [PATCH 12/18] Cleaned up the const_cast mess a little. --HG-- extra : rebase_source : d3ca36c9e2438c114afe339d1cbf704d318b6185 --- include/SDL_stdinc.h | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index a19647729..b1ce99390 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -93,9 +93,11 @@ #ifdef __cplusplus #define SDL_reinterpret_cast(type, expression) reinterpret_cast(expression) #define SDL_static_cast(type, expression) static_cast(expression) +#define SDL_const_cast(type, expression) const_cast(expression) #else #define SDL_reinterpret_cast(type, expression) ((type)(expression)) #define SDL_static_cast(type, expression) ((type)(expression)) +#define SDL_const_cast(type, expression) ((type)(expression)) #endif /*@}*//*Cast operators*/ @@ -502,49 +504,25 @@ SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); } extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c); #ifdef HAVE_STRCHR -SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { -#ifdef __cplusplus -return const_cast(strchr(str, c)); -#else -return (char*)strchr(str, c); -#endif -} +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return SDL_const_cast(char*,strchr(str, c)); } #define SDL_strchr SDL_strchr_inline #elif defined(HAVE_INDEX) /* !!! FIXME: is there anywhere that has this but not strchr? */ -SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); } +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return SDL_const_cast(char*,index(str, c)); } #define SDL_strchr SDL_strchr_inline #endif extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c); #ifdef HAVE_STRRCHR -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { -#ifdef __cplusplus -return const_cast(strrchr(str, c)); -#else -return (char*)strrchr(str, c); -#endif -} +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return SDL_const_cast(char*,strrchr(str, c)); } #define SDL_strrchr SDL_strrchr_inline #elif defined(HAVE_RINDEX) /* !!! FIXME: is there anywhere that has this but not strrchr? */ -SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { -#ifdef __cplusplus -return const_cast(rindex(str, c)); -#else -return (char*)rindex(str, c); -#endif -} +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return SDL_const_cast(char*,rindex(str, c)); } #define SDL_strrchr SDL_strrchr_inline #endif extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle); #ifdef HAVE_STRSTR -SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { -#ifdef __cplusplus -return const_cast(strstr(haystack, needle)); -#else -return (char*)strstr(haystack, needle); -#endif -} +SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return SDL_const_cast(char*,strstr(haystack, needle)); } #define SDL_strstr SDL_strstr_inline #endif From 5c189f9803fbda5915e6275f6f2356c888c283d3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 19 Apr 2013 11:58:38 -0400 Subject: [PATCH 13/18] Fixed using the event queue lock before the mutex was created. This has the benefit of ending the otherwise-bogus complaints that SDL_GetError() reports "Passed a NULL mutex" if you call it instead of checking if SDL_CreateWindow() actually succeeded. :) --HG-- extra : rebase_source : 49ed52691094eab9dd4012bb97f32fbcc678551e --- src/events/SDL_events.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index ade28a697..75aed9221 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -123,12 +123,6 @@ SDL_StartEventLoop(void) FIXME: Does this introduce any other bugs with events at startup? */ - /* No filter to start with, process most event types */ - SDL_EventOK = NULL; - SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE); - SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE); - SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE); - /* Create the lock and set ourselves active */ #if !SDL_THREADS_DISABLED if (!SDL_EventQ.lock) { @@ -138,6 +132,13 @@ SDL_StartEventLoop(void) return (-1); } #endif /* !SDL_THREADS_DISABLED */ + + /* No filter to start with, process most event types */ + SDL_EventOK = NULL; + SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE); + SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE); + SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE); + SDL_EventQ.active = 1; return (0); From be4412d0f23d8ea460cc5305a49dcfe7962265b7 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Fri, 19 Apr 2013 13:25:39 -0300 Subject: [PATCH 14/18] Fixes bug #1709, pthread tests fixes for CMake (Thanks Scott Percival!) --- cmake/sdlchecks.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake index 3638664a3..5a9139903 100644 --- a/cmake/sdlchecks.cmake +++ b/cmake/sdlchecks.cmake @@ -551,7 +551,7 @@ macro(CheckPTHREAD) if(PTHREADS) if(LINUX) set(PTHREAD_CFLAGS "-D_REENTRANT") - set(PTHREAD_LDFLAGS "-lpthread") + set(PTHREAD_LDFLAGS "-pthread") elseif(BSDI) set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE") set(PTHREAD_LDFLAGS "") @@ -607,6 +607,7 @@ macro(CheckPTHREAD) int main(int argc, char **argv) { pthread_mutexattr_t attr; pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + return 0; }" HAVE_RECURSIVE_MUTEXES) if(HAVE_RECURSIVE_MUTEXES) set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1) @@ -616,6 +617,7 @@ macro(CheckPTHREAD) int main(int argc, char **argv) { pthread_mutexattr_t attr; pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + return 0; }" HAVE_RECURSIVE_MUTEXES_NP) if(HAVE_RECURSIVE_MUTEXES_NP) set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1) @@ -624,7 +626,8 @@ macro(CheckPTHREAD) if(PTHREADS_SEM) check_c_source_compiles("#include - #include " HAVE_PTHREADS_SEM) + #include + int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM) if(HAVE_PTHREADS_SEM) check_c_source_compiles(" #include From ba5fc3539a3146859bb2697ca1efbc5b5ae8cb35 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Fri, 19 Apr 2013 14:40:39 -0300 Subject: [PATCH 15/18] Fix for bug #1776 by Jonathan Dearborn --- android-project/src/org/libsdl/app/SDLActivity.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index e0a850f42..93a5fedec 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -32,7 +32,7 @@ import java.lang.*; public class SDLActivity extends Activity { // Keep track of the paused state - public static boolean mIsPaused; + public static boolean mIsPaused = false; // Main components private static SDLActivity mSingleton; @@ -71,9 +71,6 @@ public class SDLActivity extends Activity { // So we can call stuff from static callbacks mSingleton = this; - // Keep track of the paused state - mIsPaused = false; - // Set up the surface mSurface = new SDLSurface(getApplication()); From 12a26f7c35f3d5d4a89cbfa02da4294f820e1c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Fri, 19 Apr 2013 10:51:21 -0700 Subject: [PATCH 16/18] Make gamecontroller triggers have values in 0 - 32767. This changes the old behavior of having values in the -32768 - 32767 range, like regular joystick axis. Now "button as axis" triggers (like on Logitech controllers) and regular axis triggers (like on Xbox controllers) have the same resting value, 0. --- src/joystick/SDL_gamecontroller.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index a5e388f54..7722ed5a4 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -157,7 +157,18 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) { if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) // simple axis to axis, send it through { - SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.raxes[event->jaxis.axis], event->jaxis.value ); + SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis]; + Sint16 value = event->jaxis.value; + switch (axis) + { + case SDL_CONTROLLER_AXIS_TRIGGERLEFT: + case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: + /* Shift it to be 0 - 32767. */ + value = ( value + 32768 ) / 2; + default: + break; + } + SDL_PrivateGameControllerAxis( controllerlist, axis, value ); } else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) // simlate an axis as a button { @@ -187,7 +198,7 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) } else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) // an button pretending to be an axis { - SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32768 : 0 ); + SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0 ); } break; } From e4b6ac8025dcbd426bac07417ecb90e5124ba8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Fri, 19 Apr 2013 16:02:16 -0700 Subject: [PATCH 17/18] Fix overflow in recent gamecontroller trigger change. --- src/joystick/SDL_gamecontroller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 7722ed5a4..2e856d359 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -164,7 +164,7 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) case SDL_CONTROLLER_AXIS_TRIGGERLEFT: case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: /* Shift it to be 0 - 32767. */ - value = ( value + 32768 ) / 2; + value = value / 2 + 16384; default: break; } From cf8a84626b86458721519a5dcde683b677c022f2 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Sat, 20 Apr 2013 23:05:08 -0400 Subject: [PATCH 18/18] future-proofing for Microsoft's C++/CX extensions, whereby "generic" is a reserved keyword --- include/SDL_events.h | 6 +++--- src/events/SDL_events.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index 205467e9a..fe742b237 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -124,11 +124,11 @@ typedef enum /** * \brief Fields shared by every event */ -typedef struct SDL_GenericEvent +typedef struct SDL_CommonEvent { Uint32 type; Uint32 timestamp; -} SDL_GenericEvent; +} SDL_CommonEvent; /** * \brief Window state change event data (event.window.*) @@ -464,7 +464,7 @@ typedef struct SDL_SysWMEvent typedef union SDL_Event { Uint32 type; /**< Event type, shared with all events */ - SDL_GenericEvent generic; /**< Generic event data */ + SDL_CommonEvent common; /**< Common event data */ SDL_WindowEvent window; /**< Window event data */ SDL_KeyboardEvent key; /**< Keyboard event data */ SDL_TextEditingEvent edit; /**< Text editing event data */ diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 75aed9221..ecba3bb5b 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -365,7 +365,7 @@ int SDL_PushEvent(SDL_Event * event) { SDL_EventWatcher *curr; - event->generic.timestamp = SDL_GetTicks(); + event->common.timestamp = SDL_GetTicks(); if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) { return 0; }