[Mesa-dev] [PATCH 4/4] swrast: use malloc instead of MAX_WIDTH arrays in glCopyPixels, zoom code

Eric Anholt eric at anholt.net
Tue Dec 6 11:07:15 PST 2011


On Mon,  5 Dec 2011 20:43:17 -0700, Brian Paul <brianp at vmware.com> wrote:
> diff --git a/src/mesa/swrast/s_zoom.c b/src/mesa/swrast/s_zoom.c
> index 16bb997..e832121 100644
> --- a/src/mesa/swrast/s_zoom.c
> +++ b/src/mesa/swrast/s_zoom.c
> @@ -299,11 +299,17 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span,
>         * Also, clipping may change the span end value, so store it as well.
>         */
>        const GLint end = zoomed.end; /* save */
> -      GLuint rgbaSave[MAX_WIDTH][4];
> +      void *rgbaSave;
>        const GLint pixelSize =
>           (zoomed.array->ChanType == GL_UNSIGNED_BYTE) ? 4 * sizeof(GLubyte) :
>           ((zoomed.array->ChanType == GL_UNSIGNED_SHORT) ? 4 * sizeof(GLushort)
>            : 4 * sizeof(GLfloat));
> +
> +      rgbaSave = malloc(zoomed.end * MAX_PIXEL_BYTES);
> +      if (!rgbaSave) {
> +         return;
> +      }
> +
>        if (y1 - y0 > 1) {
>           memcpy(rgbaSave, zoomed.array->rgba, zoomed.end * pixelSize);
>        }
> @@ -315,6 +321,8 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span,
>              memcpy(zoomed.array->rgba, rgbaSave, zoomed.end * pixelSize);
>           }
>        }
> +
> +      free(rgbaSave);
>     }
>  }

You've got that pixelSize value right there, let's use that instead of
MAX_PIXEL_BYTES.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20111206/ab3fd460/attachment.pgp>


More information about the mesa-dev mailing list