Evan Ovadia (Verdagon) wrote:
> struct TileType
> {
>   bool Walkable;
>   char Icon;
>   RGBColorType Color;
> };
>
    :
    :
> When I comment out the
> RGBColorType Color; line my
> application works fine. When
> it is in there, it transforms
> any characters drawn anywhere
> into garbage, and then gives a
> fatal error.
>
> One time I had an extremely
> weird case of this, and when
> the OS first came in contact
> with a RGBColorType struct, it
> just... blew up. Listen to
> what happened...
>
> And it's weird, because in the
> new version of my game, even
> having it in the structure
> causes it to crash. Nothing
> ever uses the RGBColorType
> Color;. I tried doing this:
    :
    :
> struct MyColorType
> {
>   UInt8 index, r, g, b;
> };
>
> struct TileType
> {
>   bool Walkable;
>   char Icon;
>   MyColorType Color;
> };
>
    :
    :
> and it works fine! That
> struct is identical to the
> RGBColorType.

[ First of all, please set your e-mail client to wrap lines at
something like 70 columns.  It's the standard for Internet e-mail,
and Reading everything with an entire paragraph on one line is
annoying. ]

Anyway, the definition for MyColorType that you gave is definitely
*NOT* identical to RGBColorType.  RGBColorType is defined like this:

    typedef struct RGBColorType
    {
        UInt8 index;
        UInt8 r;
        UInt8 g;
        UInt8 b;
    } RGBColorType;

Note that there is an extra field in there.

Having said that, is it possible you're allocating some array or
other data structure that includes some TileTypes without using
sizeof(TileType)?  If you are allocating too little space, it's
possible that either reading garbage from memory you don't own, or
your writing into memory that isn't yours.  That could cause a
crash.

Beyond that, it's impossible to say.  If you are not using the Color
member of the TileType struct anywhere in your code, then adding
it does not do anything at all except change the size of the struct.
Since you added it at the end, all the other members of the struct
will still be there and will have the same offset within the struct
as they did before.  So, you need to look for issues things having
to do with the length of the struct.

  - Logan

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to