# access violation (segmentation fault)*unsolved*

This topic is 5134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

it says the afformentioned error was found in my program in this line and i dont exacly know what it means array[3]=(BITMAP *)datafile[river_ver].dat,datafile [mountain].dat,datafile[plains].dat; [Edited by - raptorstrike on September 2, 2004 9:51:36 PM]

##### Share on other sites
In general, a segmentation fault (or/and a segmentation fault) arises when some part of memory is accessed which has not been allocated previously.

Without more information on the context (which compiler are you using, which operating system, which development api etc...) it's hard to find the precise answer to your question, but if I should guess, I'd think it's one of the following:

- "array" has not been sized correctly, so maybe you allocated array = new whatevertype[3]; instead of new whatevertype[4];
- same is true for datafile: size too small?

Actually, I don't quite understand the line... Which language is this?!

array[3] = {(BITMAP *) datafile[river_ver].dat, datafile[mountain].dat, datafile[plains].dat}; ??

But even that wouldn't make any sense...
Sorry for the somewhat unhelpful try of assistance; maybe you can provide some more context and I (or someone better suited) can help you further...

##### Share on other sites
i dose look kind of wierd cause im using allegro this is c++ but it is a genral debug error (not alleg. stacific so i posted it here

#include "main.h"#include "allegro.h"#include "tile.h"int main(int argc, char *argv[]){    tile the_tile;    DATAFILE *datafile;     BITMAP * array[3];     (BITMAP *) datafile[river_ver].dat;     int identifire;     int array2[2][3];     int x;     int y;     array2[2][3]=  1,2,0,2,1,0;    (BITMAP *) datafile[mountain].dat;    (BITMAP *) datafile[plains].dat;    array[3]= (BITMAP *) datafile[river_ver].dat,datafile[mountain].dat,datafile[plains].dat;       char buf[256];   allegro_init();   install_keyboard();    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED , 320, 200, 0, 0) != 0) {      set_gfx_mode(GFX_TEXT , 0, 0, 0, 0);      allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);      return 1;   set_color_depth(32);   }   /* load the datafile into memory */   replace_filename(buf, argv[0], "datafile.dat", sizeof(buf));   datafile = load_datafile(buf);   if (!datafile) {      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);      allegro_message("Error loading %s!\n", buf);      return 1;   }     int templat[2][3]={1,0,1,2,2,0};   set_palette((RGB *)datafile[main_palette].dat);   /* aha, set a palette and let Allegro convert colors when blitting */   set_color_conversion(COLORCONV_TOTAL);      /* display the bitmap from the datafile */   textout(screen, font, "This is the bitmap:", 32, 16, makecol(255, 0, 255));   the_tile.draw_tile(x,y,identifire,array,array2);         /* and use the font from the datafile */  // textout(screen, datafile[BIG_FONT].dat, "And this is a big font!", 32, 128,//	   makecol(0, 255, 0));   readkey();   /* unload the datafile when we are finished with it */   unload_datafile(datafile);   return 0;}END_OF_MAIN();

im just declaring an array of BITMAPS via a seprate data file datafile.dat and i am specifying what spacific map [river_ver] in a large set of bitmaps

EDIT: by the way my compiler (dev-cpp 4.9.9.0) dosnt like those {} around the array so thats why there not there

##### Share on other sites
Okay, I think the problem is with your array declaration:

BITMAP *array[3];

declares an array of pointers... Valid from

array[0]

to

array[2]

so, if you'd like to access the third entry, write

array[2] = ...

or increase the size.

Hth!

[Edited by - Beren77 on September 3, 2004 7:15:30 AM]

##### Share on other sites
well i fixed my function (that did go of the base of 1-3) so i did prevent a future error but this error persists its in this line

array[0]=(BITMAP *) datafile[river_ver].dat;

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• ### Forum Statistics

• Total Topics
632631
• Total Posts
3007539
• ### Who's Online (See full list)

There are no registered users currently online

×