[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: alleg-developers@xxxxxxxxxx
- Subject: [AD] About create_bitmap
- From: Chris <chris.kcat@xxxxxxxxxx>
- Date: Mon, 1 Nov 2004 17:47:06 -0800
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding; b=guExcMgKsbbddXfPbxQxHT7dV2zZmMlXPbkp+6n/pgTEhTEydTo8JPw3jQmqeEYvC7iJOAksF9lBqGdcSi7LbilDJ4Sf/4QQhgu+4vVM94YLKqmmOaw9fGIOmeDr9KR4bxuqA67xK6ch39f79tOexTO89Toapx1RKAX7n33rZSs=
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();
}
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.
- Kitty Cat