![]() |
|
access violation-newbie tile map... |
Dorianin
Member #8,013
November 2006
|
greetings and salutations, all... yet another "I'm new to yada yada yad..." here it goes...Im writing a map editor from a tutorial i got on the web.however, ive kind of developed a liking for some c++ stuff...so im modifying as i go.the tutorial is in c. i get an access violation(segmentation fault) somewhere in my Map header file. I cant quite seem to pinpoint it with the debugger...so here you guys go.im using Dev-C++ 4.9.9.2 with the current allegro devpak.
the c headers are from when i was using the c file system from the tutorial..i forgot to comment them out. never play leapfrog with a unicorn.... |
Richard Phipps
Member #1,632
November 2001
![]() |
all your for (i=0;i>MAP_SIZE;i++) should be for (i=0;i<MAP_SIZE;i++) and the same for j too. |
Dorianin
Member #8,013
November 2006
|
aright...did that...still getting the access violation... ...i narrowed it down to the datafile declaration...here the main.c code...
never play leapfrog with a unicorn.... |
Elverion
Member #6,239
September 2005
![]() |
Quote: DATAFILE* data=load_datafile("editor_tiles.dat"); You are calling that globally. That's never a good idea...avoid global variables and assignments wherever possible. You are currently calling load_datafile before Allegro is even initialized. Try this instead:
-- |
Dorianin
Member #8,013
November 2006
|
perfect...that worked.thanks... ...now...to save my map ive got a function like so... however...nothing happens...I believe my parameters may be wonky...but nothing shows up in compiling, debugging or running... never play leapfrog with a unicorn.... |
Elverion
Member #6,239
September 2005
![]() |
That's not a very good way to save your maps. If you are sure you want to do it that way, check into reinterpret_cast. Keep in mind that this would cause endianess problems, and the saved maps would not work with your program if compiled under a different compiler. I suggest you just go about writing your own save function. It's basically just something like this:
You could, of course, optimize the performance of the function by using a single for loop, and using div and mod to extract the x and y positions from a single variable. -- |
ImLeftFooted
Member #3,935
October 2003
![]() |
The parameter to the function is '_filename' yet you're passing 'filename' to fopen. Btw, if you're using C++ why not use C++'s file operators instead of C's file operators? void Map::savemap(char* _filename) { ofstream file(_filename, ios::out | ios::binary); file.write(Map,sizeof(Tile)*MAP_SIZE*MAP_SIZE); }
|
Dorianin
Member #8,013
November 2006
|
hey...your right...wonderwhy the compiler didn't catch that... i had originally tried to use thee c++ file system, but the ios:: operaters stymied me a bit...but that seems very nice...thank you all for the help... never play leapfrog with a unicorn.... |
|