Array bounds overflow?

Hey there. Im having an issue with a array bounds overflow that makes no sense to me:

Code:

#define MAP_W 16
#define MAP_H 16
typedef char map_data[MAP_H][MAP_W];

map_data level_map = {
/* 0123456789ABCDEF*/
" 000050010000000", //0
"0000000010000000", //1
"0000000010000000", //2
"1110000010000111", //3
"0000000010000000", //4
"0000000010000000", //5
"1111111010000000", //6
"0000000110000000", //7
"0000000010000000", //8
"0000000000000000", //9
"0000000000000000", //A
"0000000000000000", //B
"0000000000000000", //C
"0000000000000000", //D
"0000000000000000", //E
"0000000000000000" //F
};

Okay so…I made an array, 16x16, fill it up and then when i try to compile (VC++) this comes up:

c:\tutorial\copy of copy of plat_engine\plat_engine\plat_engine\main.cpp(5) : error C2117: ‘level_map’ : array bounds overflow
c:\tutorial\copy of copy of plat_engine\plat_engine\plat_engine\main.cpp(3) : see declaration of 'level_map’
c:\tutorial\copy of copy of plat_engine\plat_engine\plat_engine\main.cpp(5) : error C2078: too many initializers

More, it gives the error for each line (same error). So, what am i doing wrong? this makes no sense to me >_<

A string literal includes the terminating ‘\0’, so MAP_H should be 17,
not 16.On Fri, 27 Nov 2009 15:19:10 -0800 Tabris wrote:

Hey there. Im having an issue with a array bounds overflow that makes
no sense to me:

“0000000010000000”, //1

… those are strings. null termination is killing you (adding an extra
byte).

-willOn Fri, Nov 27, 2009 at 5:19 PM, Tabris wrote:

Hey there. Im having an issue with a array bounds overflow that makes no
sense to me:

Code:

#define MAP_W 16
#define MAP_H 16
typedef char map_data[MAP_H][MAP_W];

map_data level_map = {
/* 0123456789ABCDEF*/
" 000050010000000", //0
"0000000010000000", //1
"0000000010000000", //2
"1110000010000111", //3
"0000000010000000", //4
"0000000010000000", //5
"1111111010000000", //6
"0000000110000000", //7
"0000000010000000", //8
"0000000000000000", //9
"0000000000000000", //A
"0000000000000000", //B
"0000000000000000", //C
"0000000000000000", //D
"0000000000000000", //E
"0000000000000000" //F
};

Okay so…I made an array, 16x16, fill it up and then when i try to compile
(VC++) this comes up:

c:\tutorial\copy of copy of plat_engine\plat_engine\plat_engine\main.cpp(5)
: error C2117: ‘level_map’ : array bounds overflow
c:\tutorial\copy of copy of plat_engine\plat_engine\plat_engine\main.cpp(3)
: see declaration of 'level_map’
c:\tutorial\copy of copy of plat_engine\plat_engine\plat_engine\main.cpp(5)
: error C2078: too many initializers

More, it gives the error for each line (same error). So, what am i doing
wrong? this makes no sense to me >_<


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You could also use a simple image file format as your map format. Use
an indexed palette, and assign each color a different meaning. Then
you can use your favorite image editor!

The GIMP has a file format plug-in for exporting C code not unlike
what you’re trying to do, but I just tried it with an indexed palette,
and shockingly it doesn’t seem to support them!

It would be trivial to write an SDL+SDL_image program to load an
indexed palette image in PNG format or whatever and output some C code
if that’s what you really want :)On Fri, Nov 27, 2009 at 6:43 PM, Tim Angus wrote:

On Fri, 27 Nov 2009 15:19:10 -0800 Tabris wrote:

Hey there. Im having an issue with a array bounds overflow that makes
no sense to me:

? ? ? “0000000010000000”, //1

A string literal includes the terminating ‘\0’, so MAP_H should be 17,
not 16.


http://codebad.com/

Hey there. Im having an issue with a array bounds overflow that makes
no sense to me:

  "0000000010000000", //1

A string literal includes the terminating ‘\0’, so MAP_H should be 17,
not 16.

You could also use a simple image file format as your map format. Use
an indexed palette, and assign each color a different meaning. Then
you can use your favorite image editor!

Not quite sure what that buys you, compared to using a text editor, but
anyway… :slight_smile:

There are a few editors actually designed for this stuff. Google for “tiled
map editor” and similar.

Here’s one that claims to be “generic”:
http://mapeditor.org/

Here’s a more advanced alternative, that comes with “playback” libraries for
various platforms and APIs, including SDL:
http://www.tilemap.co.uk/mappy.php

Another one that should output in any format you want (programmable), and
appears to be Free/Open Source:
http://tilestudio.sourceforge.net/

The GIMP has a file format plug-in for exporting C code not unlike
what you’re trying to do, but I just tried it with an indexed palette,
and shockingly it doesn’t seem to support them!

You don’t really need a special plug-in, though. The .XPM format is actually
in C source format, though slightly more complex than just raw “one byte per
pixel”.
http://en.wikipedia.org/wiki/X_PixMapOn Saturday 28 November 2009, at 05.20.55, Donny Viszneki <donny.viszneki at gmail.com> wrote:

On Fri, Nov 27, 2009 at 6:43 PM, Tim Angus wrote:

On Fri, 27 Nov 2009 15:19:10 -0800 Tabris wrote:


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’

You could also use a simple image file format as your map format. Use
an indexed palette, and assign each color a different meaning. Then
you can use your favorite image editor!

Not quite sure what that buys you, compared to using a text editor, but
anyway… :slight_smile:

Many text editors do not have rectangular copy-and-paste.

I have never found a text editor that supports flood-fill.

Colors!

There are a few editors actually designed for this stuff. Google for “tiled
map editor” and similar.

Here’s one that claims to be “generic”:
? ? ? ?http://mapeditor.org/

Another one that should output in any format you want (programmable), and
appears to be Free/Open Source:
? ? ? ?http://tilestudio.sourceforge.net/

Both Tiled and Tile Studio support being extended with custom file
formats. Hell, you have the source code for both, you could make them
do that without too much trouble even if they didn’t claim that,
unless they were astoundingly convoluted.

The GIMP has a file format plug-in for exporting C code not unlike
what you’re trying to do, but I just tried it with an indexed palette,
and shockingly it doesn’t seem to support them!

You don’t really need a special plug-in, though. The .XPM format is actually
in C source format,

Yeah well it’s not hard to write a gimp plugin. For simple file
formats, you can write one in Python, Perl, or any other language
supported by GimpFu in roughly 20-80 lines of code.

though slightly more complex than just raw “one byte per
pixel”.

I’d say so:

/* XPM /
static char * example_xpm[] = {
“16 16 23 1”,
" c #FFFFFF",
". c #000000",
"+ c #FF0000",
"@ c #FF00FF",
"# c #0000FF",
"$ c #00FFFF",
"% c #00FF00",
"& c #FFFF00",
"
c #7F0000",
"= c #7F007F",
"- c #00007F",
"; c #007F7F",
"> c #007F00",
", c #827F00",
"’ c #191919",
") c #333333",
"! c #4C4C4C",
"~ c #666666",
"{ c #7F7F7F",
"] c #999999",
"^ c #B2B2B2",
"/ c #CCCCCC",
"( c #E5E5E5",
" $ . “,
” . “,
” . “,
” . “,
” . “,
”… . …",
" . “,
” . “,
” . “,
”… . “,
” … “,
” . “,
” “,
” “,
” “,
” "};On Sat, Nov 28, 2009 at 12:03 PM, David Olofson wrote:

On Saturday 28 November 2009, at 05.20.55, Donny Viszneki <@Donny_Viszneki> wrote:


http://codebad.com/

You could also use a simple image file format as your map format. Use
an indexed palette, and assign each color a different meaning. Then
you can use your favorite image editor!

Not quite sure what that buys you, compared to using a text editor, but
anyway… :slight_smile:

Many text editors do not have rectangular copy-and-paste.

I have never found a text editor that supports flood-fill.

Ah… Good points. The editors I use do have “block mode”, as they call it -
but I don’t think I’ve seen flood fill either…!

Colors!

Well, you could roll a custom syntax highlighting definition… :wink:

There are a few editors actually designed for this stuff. Google for
"tiled map editor" and similar.

Here’s one that claims to be “generic”:
http://mapeditor.org/

Another one that should output in any format you want (programmable), and
appears to be Free/Open Source:
http://tilestudio.sourceforge.net/

Both Tiled and Tile Studio support being extended with custom file
formats. Hell, you have the source code for both, you could make them
do that without too much trouble even if they didn’t claim that,
unless they were astoundingly convoluted.

I think the “programmable output format” feature claim mean you can change it
in the configuration options or something - but it doesn’t really matter much
for programmers using open source applications. :slight_smile:

The GIMP has a file format plug-in for exporting C code not unlike
what you’re trying to do, but I just tried it with an indexed palette,
and shockingly it doesn’t seem to support them!

You don’t really need a special plug-in, though. The .XPM format is
actually in C source format,

Yeah well it’s not hard to write a gimp plugin. For simple file
formats, you can write one in Python, Perl, or any other language
supported by GimpFu in roughly 20-80 lines of code.

Sure, but there is some learning curve, unless you already know your ways
around GIMP and one of the supported scripting languages.

though slightly more complex than just raw “one byte per
pixel”.

I’d say so:

/* XPM */
static char * example_xpm[] = {
“16 16 23 1”,
" c #FFFFFF",
". c #000000",
[…]

Right - but you can compile it into your source, and SDL_image can turn it
into an SDL_surface, if you prefer that format.

Either way, I still think a proper map editor is the only sensible choice for
any non-trivial map editing. :-)On Saturday 28 November 2009, at 18.20.57, Donny Viszneki <donny.viszneki at gmail.com> wrote:

On Sat, Nov 28, 2009 at 12:03 PM, David Olofson <@David_Olofson> wrote:

On Saturday 28 November 2009, at 05.20.55, Donny Viszneki <donny.viszneki at gmail.com> wrote:


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’

David Olofson writes:> On Saturday 28 November 2009, at 18.20.57, Donny Viszneki <donny.viszneki at gmail.com> wrote:

On Sat, Nov 28, 2009 at 12:03 PM, David Olofson wrote:

On Saturday 28 November 2009, at 05.20.55, Donny Viszneki <donny.viszneki at gmail.com> wrote:

You could also use a simple image file format as your map format. Use
an indexed palette, and assign each color a different meaning. Then
you can use your favorite image editor!

Not quite sure what that buys you, compared to using a text editor, but
anyway… :slight_smile:

Many text editors do not have rectangular copy-and-paste.

I have never found a text editor that supports flood-fill.

Ah… Good points. The editors I use do have “block mode”, as they call it -
but I don’t think I’ve seen flood fill either…!

emacs of course has :wink: in artist-mode [0]
C-c C-a f artist-select-op-flood-fill

     ....           ....
    .####.         .####.
   .######.        .####.
    .####.          .##..
     ....            ..

       .......     .........
        .#####.....#######.
         .###############.
          ...............

[0] http://www.emacswiki.org/emacs/ArtistMode

[…]

David Olofson <@David_Olofson> writes:
[…]

Many text editors do not have rectangular copy-and-paste.

I have never found a text editor that supports flood-fill.

Ah… Good points. The editors I use do have “block mode”, as they call
it - but I don’t think I’ve seen flood fill either…!

emacs of course has :wink: in artist-mode [0]
C-c C-a f artist-select-op-flood-fill

     ....           ....
    .####.         .####.
   .######.        .####.
    .####.          .##..
     ....            ..

       .......     .........
        .#####.....#######.
         .###############.
          ...............

Cool! :smiley:

Well, emacs is not a text editor, but the Universal Tool of All Time, so that
figures. ;-)On Saturday 28 November 2009, at 22.17.22, Jens Thiele wrote:

On Saturday 28 November 2009, at 18.20.57, Donny Viszneki <donny.viszneki at gmail.com> wrote:


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’