[SDL] "Text has zero width" isn't an error.
donny.viszneki at gmail.com
Wed Apr 8 11:28:56 PDT 2009
On Wed, Apr 8, 2009 at 2:10 PM, Stefan Monov <logixoul at gmail.com> wrote:
> First, to answer your question. Currently RenderUTF8 can produce the
> following errors:
> - "string has zero width"
> - "failed to allocate text surface"
> - "failed to find glyph"
How annoying. I am always thrown for a loop whenever software returns
any error as string-only so that the program cannot comfortably handle
>> I'm a little confused as to why returning no surface when there is no
>> data to be on that surface is being interpreted by some as a problem.
> Here's where we diverge: I say there _is_ data to be on the surface,
Where we diverge is that when you say "surface" you mean SDL_Surface,
and when I say it I mean the notional surface/canvas represented by
> and the data happens to be an empty string.
> For example, the following should be correct usage of SDL_ttf:
> SDL_Surface* surface = TTF_RenderUTF8_Blended(font, myTextVar, myColorVar);
> myButton.resize(surface->w, surface->h);
> SDL_BlitSurface(surface, NULL, screen, NULL);
I understand. I think this proves, however, that there are examples
which favor both approaches. In your situation, since you seem to be
using C++, why not just create a wrapper around SDL_Surface which will
return 0 for its dimensions when its internal SDL_Surface pointer is
> Jonathan says:
>> It is a lot less computation to return NULL rather than
>> a fully-initialised 0x0 surface with all its fields...
> True. However, is this not a pointless thing to optimize? The cost of
> constructing a 0x0 surface is dwarfed even by that of say, blitting a
> 32x32 sprite of which there are thousands in an application...
Well, you can't predict the allocation overhead for all platforms.
>> Actually, now that I think of it, if you're using SDL_BlitSurface(),
>> it doesn't care if you pass a NULL surface. What is the use case
> Mainly, to be able to query width and height without needless checks.
For clarity: there are cases which favor both approaches.
> See code sample above.
> Also, not all functions in real-world code are documented to be no-ops
> when passed a NULL surface.
> For example, SDL_gfx's rotozoomSurface just might crash if passed
> NULL. You can't know.
Stefan presents a lot of cases which favor his approach.
Am I being stubborn if I say rotozoomSurface *should* crash if passed
a NULL pointer or a no-pixel surface? I frequently argue in favor of
more checking when they aren't very expensive, but secretly I wonder
if we're all such bad hackers that we can't accept a segfault to show
us exactly where the *one* check *should* have been...
More information about the SDL