mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-03 08:28:29 +00:00
Small stack allocations fall back to malloc if they're unexpectedly large.
This commit is contained in:
@@ -2176,8 +2176,9 @@ RenderDrawPointsWithRects(SDL_Renderer * renderer,
|
||||
SDL_FRect *frects;
|
||||
int i;
|
||||
int retval = -1;
|
||||
SDL_bool isstack;
|
||||
|
||||
frects = SDL_stack_alloc(SDL_FRect, count);
|
||||
frects = SDL_small_alloc(SDL_FRect, count, &isstack);
|
||||
if (!frects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -2190,7 +2191,7 @@ RenderDrawPointsWithRects(SDL_Renderer * renderer,
|
||||
|
||||
retval = QueueCmdFillRects(renderer, frects, count);
|
||||
|
||||
SDL_stack_free(frects);
|
||||
SDL_small_free(frects, isstack);
|
||||
|
||||
return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
|
||||
}
|
||||
@@ -2202,6 +2203,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer,
|
||||
SDL_FPoint *fpoints;
|
||||
int i;
|
||||
int retval;
|
||||
SDL_bool isstack;
|
||||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
@@ -2221,7 +2223,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer,
|
||||
return RenderDrawPointsWithRects(renderer, points, count);
|
||||
}
|
||||
|
||||
fpoints = SDL_stack_alloc(SDL_FPoint, count);
|
||||
fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
|
||||
if (!fpoints) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -2232,7 +2234,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer,
|
||||
|
||||
retval = QueueCmdDrawPoints(renderer, fpoints, count);
|
||||
|
||||
SDL_stack_free(fpoints);
|
||||
SDL_small_free(fpoints, isstack);
|
||||
|
||||
return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
|
||||
}
|
||||
@@ -2258,8 +2260,9 @@ RenderDrawLinesWithRects(SDL_Renderer * renderer,
|
||||
SDL_FPoint fpoints[2];
|
||||
int i, nrects = 0;
|
||||
int retval = 0;
|
||||
SDL_bool isstack;
|
||||
|
||||
frects = SDL_stack_alloc(SDL_FRect, count-1);
|
||||
frects = SDL_small_alloc(SDL_FRect, count-1, &isstack);
|
||||
if (!frects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -2295,7 +2298,7 @@ RenderDrawLinesWithRects(SDL_Renderer * renderer,
|
||||
|
||||
retval += QueueCmdFillRects(renderer, frects, nrects);
|
||||
|
||||
SDL_stack_free(frects);
|
||||
SDL_small_free(frects, isstack);
|
||||
|
||||
if (retval < 0) {
|
||||
retval = -1;
|
||||
@@ -2310,6 +2313,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer,
|
||||
SDL_FPoint *fpoints;
|
||||
int i;
|
||||
int retval;
|
||||
SDL_bool isstack;
|
||||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
@@ -2329,7 +2333,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer,
|
||||
return RenderDrawLinesWithRects(renderer, points, count);
|
||||
}
|
||||
|
||||
fpoints = SDL_stack_alloc(SDL_FPoint, count);
|
||||
fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
|
||||
if (!fpoints) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -2340,7 +2344,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer,
|
||||
|
||||
retval = QueueCmdDrawLines(renderer, fpoints, count);
|
||||
|
||||
SDL_stack_free(fpoints);
|
||||
SDL_small_free(fpoints, isstack);
|
||||
|
||||
return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
|
||||
}
|
||||
@@ -2426,6 +2430,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer,
|
||||
SDL_FRect *frects;
|
||||
int i;
|
||||
int retval;
|
||||
SDL_bool isstack;
|
||||
|
||||
CHECK_RENDERER_MAGIC(renderer, -1);
|
||||
|
||||
@@ -2441,7 +2446,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer,
|
||||
return 0;
|
||||
}
|
||||
|
||||
frects = SDL_stack_alloc(SDL_FRect, count);
|
||||
frects = SDL_small_alloc(SDL_FRect, count, &isstack);
|
||||
if (!frects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -2454,7 +2459,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer,
|
||||
|
||||
retval = QueueCmdFillRects(renderer, frects, count);
|
||||
|
||||
SDL_stack_free(frects);
|
||||
SDL_small_free(frects, isstack);
|
||||
|
||||
return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
|
||||
}
|
||||
|
@@ -1348,10 +1348,11 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
|
||||
/* Flip the rows to be top-down if necessary */
|
||||
if (!renderer->target) {
|
||||
SDL_bool isstack;
|
||||
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
||||
dst = (Uint8*)temp_pixels;
|
||||
tmp = SDL_stack_alloc(Uint8, length);
|
||||
tmp = SDL_small_alloc(Uint8, length, &isstack);
|
||||
rows = rect->h / 2;
|
||||
while (rows--) {
|
||||
SDL_memcpy(tmp, dst, length);
|
||||
@@ -1360,7 +1361,7 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
dst += temp_pitch;
|
||||
src -= temp_pitch;
|
||||
}
|
||||
SDL_stack_free(tmp);
|
||||
SDL_small_free(tmp, isstack);
|
||||
}
|
||||
|
||||
status = SDL_ConvertPixels(rect->w, rect->h,
|
||||
|
@@ -340,11 +340,12 @@ CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, co
|
||||
ctx->glCompileShaderARB(shader);
|
||||
ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
||||
if (status == 0) {
|
||||
SDL_bool isstack;
|
||||
GLint length;
|
||||
char *info;
|
||||
|
||||
ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
||||
info = SDL_stack_alloc(char, length+1);
|
||||
info = SDL_small_alloc(char, length+1, &isstack);
|
||||
ctx->glGetInfoLogARB(shader, length, NULL, info);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER,
|
||||
"Failed to compile shader:\n%s%s\n%s", defines, source, info);
|
||||
@@ -352,7 +353,7 @@ CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, co
|
||||
fprintf(stderr,
|
||||
"Failed to compile shader:\n%s%s\n%s", defines, source, info);
|
||||
#endif
|
||||
SDL_stack_free(info);
|
||||
SDL_small_free(info, isstack);
|
||||
|
||||
return SDL_FALSE;
|
||||
} else {
|
||||
|
@@ -972,10 +972,11 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
|
||||
/* Flip the rows to be top-down if necessary */
|
||||
if (!renderer->target) {
|
||||
SDL_bool isstack;
|
||||
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
||||
dst = (Uint8*)temp_pixels;
|
||||
tmp = SDL_stack_alloc(Uint8, length);
|
||||
tmp = SDL_small_alloc(Uint8, length, &isstack);
|
||||
rows = rect->h / 2;
|
||||
while (rows--) {
|
||||
SDL_memcpy(tmp, dst, length);
|
||||
@@ -984,7 +985,7 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
dst += temp_pitch;
|
||||
src -= temp_pitch;
|
||||
}
|
||||
SDL_stack_free(tmp);
|
||||
SDL_small_free(tmp, isstack);
|
||||
}
|
||||
|
||||
status = SDL_ConvertPixels(rect->w, rect->h,
|
||||
|
@@ -601,19 +601,20 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type)
|
||||
compileSuccessful = GL_TRUE;
|
||||
}
|
||||
if (!compileSuccessful) {
|
||||
SDL_bool isstack = SDL_FALSE;
|
||||
char *info = NULL;
|
||||
int length = 0;
|
||||
|
||||
data->glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length);
|
||||
if (length > 0) {
|
||||
info = SDL_stack_alloc(char, length);
|
||||
info = SDL_small_alloc(char, length, &isstack);
|
||||
if (info) {
|
||||
data->glGetShaderInfoLog(entry->id, length, &length, info);
|
||||
}
|
||||
}
|
||||
if (info) {
|
||||
SDL_SetError("Failed to load the shader: %s", info);
|
||||
SDL_stack_free(info);
|
||||
SDL_small_free(info, isstack);
|
||||
} else {
|
||||
SDL_SetError("Failed to load the shader");
|
||||
}
|
||||
@@ -1814,10 +1815,11 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
|
||||
/* Flip the rows to be top-down if necessary */
|
||||
if (!renderer->target) {
|
||||
SDL_bool isstack;
|
||||
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
||||
dst = (Uint8*)temp_pixels;
|
||||
tmp = SDL_stack_alloc(Uint8, length);
|
||||
tmp = SDL_small_alloc(Uint8, length, &isstack);
|
||||
rows = rect->h / 2;
|
||||
while (rows--) {
|
||||
SDL_memcpy(tmp, dst, length);
|
||||
@@ -1826,7 +1828,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
dst += temp_pitch;
|
||||
src -= temp_pitch;
|
||||
}
|
||||
SDL_stack_free(tmp);
|
||||
SDL_small_free(tmp, isstack);
|
||||
}
|
||||
|
||||
status = SDL_ConvertPixels(rect->w, rect->h,
|
||||
|
Reference in New Issue
Block a user