View Single Post
  #8   (View Single Post)  
Old 25th September 2011
ocicat ocicat is offline
Join Date: Apr 2008
Posts: 3,295

Originally Posted by xmorg View Post
Code here

I have managed to work around the save crash by having it create 40 "region files" when saving the world instead of one giant save file. The program now works up to the character generator, and only crashes now in macosx (works fine in bsd)
I looked briefly at your code. Given the behavior & error messages mentioned, I still am of the opinion that your code is walking into unallocated memory. Where, I did not discern. However, here are a few more thoughts on what can be done to find the problems:
  • I didn't determine whether wm->height & wm->width were being assigned only once, but these values are frequently used as upper bounds in for-loops when iterating through the overall structure. You will want to make sure these values aren't changed past the point of allocation.
  • I did notice that in write_world_file(), wm->height & wm->width are defined as type long, but the indexes used were of type int. Making the indexes the same type as the upper bound is a good idea.
  • Write independent test code on the side which simply creates the structure with anticipated fixed sizes, write to each location in the structure, and read & write to a file. Start with very small sizes & ensure that reading & writing works. Once this is verified, increase the sizes & ensure that reading & writing still works. I still believe that some memory access is happening past what has been allocated. A simplified test case will make it easier to pinpoint the problem.
Reply With Quote