Re: [AD] About create_bitmap

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Mon, 2004-11-01 at 17:47 -0800, Chris wrote:
> I recently ran into this problem when using create_bitmap. Wouldn't it
> make more sense to have create_bitmap(_ex) check for valid values (w>0
> and h>0) and return NULL if they aren't acceptable rather than
> ASSERT'ing? It's not a time-sensitive function so I don't think a
> couple if() checks will be a problem. But it becomes a chore when you
> have to check manually for >=0 values and if the returned bitmap is
> NULL, when more often than not you'd do the same for either error. So
> instead of simply doing:
> 
> bmp = create_bitmap(w, h);
> if(!bmp)
> {
>    error();
> }
> 
> you have to do:
> 
> bmp = NULL;
> if (w > 0 && h > 0)
> {
>    bmp = create_bitmap(w, h);
> }
> if(!bmp)
> {
>    error();
> }
> 

Well, you could use a simple #define. The vast majority of uses of
create_bitmap will not need a check - so this is a very special use.
There's of course no problem with create_bitmap, nobody would notice it.
But in general, I don't think it is a good idea. Else, we end up having
error checking for every single function, like OpenGL.

> Beyond that, create_bitmap_ex allows a width of 0, which will cause a
> data allocation size of 0. The bitmap will be created, but once you
> try to access the image data.. boom.
> 

That should be changed to disallow 0 I think.. I'm not sure why it was
done.

-- 
Elias Pschernig





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/