Advertisement

saving a map...

Started by April 23, 2002 05:49 PM
6 comments, last by flucknugget 22 years, 7 months ago
I'm trying to save a map to disk from a map editor I'm making, but for some reason it just closes the program.
  FILE *file;
file = fopen(filename, "wb");

/* check to see if the file opened correctly, etc. */

// save it all

fwrite(sig, sizeof(const char), sizeof(sig), file);
fwrite(map.map1, sizeof(const char), sizeof(map.map1), file);
fwrite(map.map2, sizeof(const char), sizeof(map.map2), file);
fwrite(&map.tileset, sizeof(int), 1, file);
fwrite(map.s1, sizeof(const char), 80, file);
fwrite(map.s2, sizeof(const char), 80, file);
fwrite(map.s3, sizeof(const char), 80, file);
fwrite(map.s4, sizeof(const char), 80, file);
fwrite(map.s5, sizeof(const char), 80, file);

// close the file

fclose(file);    
sig is a signature that I'm writing the map first, to validate that it's actually a map. That works fine. map.map1 and map.map2 are both single dimensional integer arrays. map.tileset is an int. map.s1 through map.s5 are character arrays. It writes sig fine, but then when it tries writing map.map1, it just crashes. Am I doing something wrong? EDIT: And by crashes, I mean closes the program without any sort of errors, not even one of those "Your program has caused an illegal operation" things or a Microsoft box asking me if I want to report the error to them. Oh yeah, and I'm using Visual C++ 6. [edited by - flucknugget on April 23, 2002 6:51:03 PM]
- f l u c k y p o o
Are you running the debug build? Try stepping through the code. If the program closes after a certain line is executed, step in fwrite and step over there. Repeat until someone calls exit(), abort() or similar. Also try _CrtSetReportMode(for all, _CRTDBG_MODE_DEBUG); and watch debug output.
---visit #directxdev on afternet <- not just for directx, despite the name
Advertisement
I''m actually using Allegro with Visual C++, which, for some reason, doesn''t let the debugger work with it.
- f l u c k y p o o
What exactly do you mean by that?
---visit #directxdev on afternet <- not just for directx, despite the name
Allegro is kind of weird. In order to set it up in VC++, you have to make a Win32 Application and add the alleg.lib library. Then it''s just like DOS programming, only it compiles a windows program, and there are a couple windows-only functions, like changing what it says at the top of the window, if you''re not running in fullscreen mode. At the end of your main() function, you have to put END_OF_MAIN(); after the closing brace.

When you try stepping through the program, it''s just immediately goes to the last line of the main function and then just doesn''t work past there. So I''ve always just quit the debugger. But do you see anything wrong with my code?
- f l u c k y p o o
Maybe you can post the definition of the type that "map" is of?

You can put a breakpoint (F9) at the beginning of any function, and the debugger will stop there, even if you can''t step into that function from main. You can also use Ctrl-F10 to run to that source line.
---visit #directxdev on afternet <- not just for directx, despite the name
Advertisement
Well that was weird... I set a breakpoint and ran it. It did stop at the line of code, but it wouldn''t let me select the program to try and save.. but actually, now that I think about it, it probably did, it just didn''t update the screen because it was stopped at a breakpoint. So anyway, I continue stepping through a little while, then it crashed on a blit for some reason, that it never crashed on before when I was running it normally. I could see it maybe doing that if the blit was writing to video memory, but it wasn''t. And anyway, here''s the map structure.


  struct MAP_STRUCT{	int map1[30*20];	int map2[30*20];	int tileset;	char s1[80];	char s2[80];	char s3[80];	char s4[80];	char s5[80];};MAP_STRUCT map;  
- f l u c k y p o o
Ahh, nevermind. The problem wasn''t with that code, it was some Allegro thing. I used a function that opens a file select dialog box, and for some reason that was causing it. But I wrote my own function now and it no longer crashes.
- f l u c k y p o o

This topic is closed to new replies.

Advertisement