[PATCH] [try 4] ddraw: Grow indexbuffer as needed

Alexandre Julliard julliard at winehq.org
Fri Jun 25 09:19:44 CDT 2010


Mikko Rasa <tdb at tdb.fi> writes:

> +    /* check that the buffer is large enough to hold the indices,
> +     * reallocate if necessary.
> +     */
> +    hr = IWineD3DBuffer_GetDesc(This->indexbuffer, &desc);
> +    if(desc.Size < IndexCount * sizeof(WORD))
> +    {
> +        UINT size = desc.Size;
> +        IWineD3DBuffer *buffer;
> +        IUnknown *parent;
> +
> +        while(size < IndexCount * sizeof(WORD))
> +        {
> +            size <<= 1;
> +            /* We keep adding zero bits to the right, so an overflow
> +             * will eventually result in all zeroes.  Detect this to
> +             * avoid infinite loop.
> +             */
> +            if(!size)
> +            {
> +                ERR("UINT overflow while trying to grow indexbuffer to hold %u indices\n", IndexCount);
> +                LeaveCriticalSection(&ddraw_cs);
> +                return D3DERR_TOOMANYPRIMITIVES;
> +            }
> +        }

A simple "size = max(desc.Size*2,IndexCount*sizeof(WORD))" would do just as
well.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list