NaN {l Wrote}:It will compile under win7/mingw with a few ifdefs here and there (the code is using a few posix functions). The game will segfault at start though. Haven't had time to really look into it. Does the game depend on a specific random implementation? I had to replace it with rand/srand.
- {l Code}: {l Select All Code}
#0 76B39F40 msvcrt!memmove() (C:\Windows\syswow64\msvcrt.dll:??)
#1 004142E5 insert_points(host_list=0x28eb04, nhost=0x28faa4, injection=0x28d848, ninject=1, injection_point=372) (D:\Word War VI\wordwarvi\wordwarvi.c:8964)
#2 00414619 peak_roof(building=0x28eb04, npoints=0x28faa4, left=371, right=372) (D:\Word War VI\wordwarvi\wordwarvi.c:9029)
#3 00414B5F embellish_roof(building=0x28eb04, npoints=0x28faa4, left=371, right=372) (D:\Word War VI\wordwarvi\wordwarvi.c:9133)
#4 00414B03 indent_roof(building=0x28eb04, npoints=0x28faa4, left=369, right=370) (D:\Word War VI\wordwarvi\wordwarvi.c:9105)
#5 00414BCB embellish_roof(building=0x28eb04, npoints=0x28faa4, left=369, right=370) (D:\Word War VI\wordwarvi\wordwarvi.c:9140)
#6 0041489C turret_roof(building=0x28eb04, npoints=0x28faa4, left=367, right=368) (D:\Word War VI\wordwarvi\wordwarvi.c:9074)
#7 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=367, right=368) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#8 0041489C turret_roof(building=0x28eb04, npoints=0x28faa4, left=365, right=366) (D:\Word War VI\wordwarvi\wordwarvi.c:9074)
#9 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=365, right=366) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#10 004148D8 turret_roof(building=0x28eb04, npoints=0x28faa4, left=338, right=339) (D:\Word War VI\wordwarvi\wordwarvi.c:9076)
#11 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=338, right=339) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#12 0041489C turret_roof(building=0x28eb04, npoints=0x28faa4, left=336, right=337) (D:\Word War VI\wordwarvi\wordwarvi.c:9074)
#13 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=336, right=337) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#14 00414914 turret_roof(building=0x28eb04, npoints=0x28faa4, left=325, right=326) (D:\Word War VI\wordwarvi\wordwarvi.c:9077)
#15 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=325, right=326) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#16 0041489C turret_roof(building=0x28eb04, npoints=0x28faa4, left=323, right=324) (D:\Word War VI\wordwarvi\wordwarvi.c:9074)
#17 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=323, right=324) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#18 00414914 turret_roof(building=0x28eb04, npoints=0x28faa4, left=307, right=308) (D:\Word War VI\wordwarvi\wordwarvi.c:9077)
#19 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=307, right=308) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#20 0041489C turret_roof(building=0x28eb04, npoints=0x28faa4, left=305, right=306) (D:\Word War VI\wordwarvi\wordwarvi.c:9074)
#21 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=305, right=306) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#22 0041489C turret_roof(building=0x28eb04, npoints=0x28faa4, left=303, right=304) (D:\Word War VI\wordwarvi\wordwarvi.c:9074)
#23 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=303, right=304) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
#24 00414B03 indent_roof(building=0x28eb04, npoints=0x28faa4, left=301, right=302) (D:\Word War VI\wordwarvi\wordwarvi.c:9105)
#25 00414BCB embellish_roof(building=0x28eb04, npoints=0x28faa4, left=301, right=302) (D:\Word War VI\wordwarvi\wordwarvi.c:9140)
#26 00414ADD indent_roof(building=0x28eb04, npoints=0x28faa4, left=297, right=298) (D:\Word War VI\wordwarvi\wordwarvi.c:9104)
#27 00414BCB embellish_roof(building=0x28eb04, npoints=0x28faa4, left=297, right=298) (D:\Word War VI\wordwarvi\wordwarvi.c:9140)
#28 0041489C turret_roof(building=0x28eb04, npoints=0x28faa4, left=295, right=296) (D:\Word War VI\wordwarvi\wordwarvi.c:9074)
#29 00414B84 embellish_roof(building=0x28eb04, npoints=0x28faa4, left=295, right=296) (D:\Word War VI\wordwarvi\wordwarvi.c:9135)
Hmm, that looks like a similar bug reported on FreeBSD that I could never replicate on linux, nor figure out by inspection what the heck was going wrong. But, if it is the same problem, you may be able to get around it by commenting out this line:
- {l Code}: {l Select All Code}
11359 add_buildings(&terrain);/* Some FreeBSD users report that */
11360 /*add_buildings() causes crashes. */
11361 /* Commenting this out on FreeBSD */
11362 /* may help, but, no buildings. */
11363 /* I've looked at the code, but */
11364 /* don't see anything wrong with it. */
and see if that helps. The cost will be, no buildings. The buildings are only scenery though, so it should not affect gameplay (though, it may slight affect the initial locations of various enemies in the game as all that is procedurally generated from a fixed random seed, so perturbing the algorithm by omitting the buildings will make the levels come out slightly different.)
The code that generates the buildings is recursive, maybe something weird is going wrong and it's blowing the stack? Kind of what it looks like in that stack trace. I've stared at thet code (ages ago) for a long time without seeing anything that looks wrong, but sometimes you're blind to your own mistakes. Clearly something's wrong in there. Don't know why it doesn't show up on linux.
Thanks for giving this a try, and may you emerge victorious!
-- steve
p.s.
Looking at that stack trace a bit more, it does not really look quite the same as the FreeBSD stack trace.
It looks like this code:
- {l Code}: {l Select All Code}
9120 static void embellish_roof(struct my_point_t *building, int *npoints, int left, int right)
9121 {
9122 int r = randomn(10);
9123
9124 switch (r) {
9125 case 1: peak_roof(building, npoints, left, right);
9126 break;
9127 case 2:turret_roof(building, npoints, left, right);
9128 break;
is always choosing case 2.
Now why would that be?
randomn() function looks like this:
- {l Code}: {l Select All Code}
2645 /* get a random number between 0 and n-1... fast and loose algorithm. */
2646 static inline int randomn(int n)
2647 {
2648 /* return (int) (((random() + 0.0) / (RAND_MAX + 0.0)) * (n + 0.0) ); */
2649 /* floating point divide? No. */
2650 return ((random() & 0x0000ffff) * n) >> 16;
2651 }
Which is my attempt at an optimized way of scaling sorta-random integers.
You mentioned using srand and rand instead of random().
I notice now that random() returns a long int, and rand returns an int.
Maybe that's the difference? (although, I'm surprised random() returns a long int
when I wrote the above code, my assumption was that it returned and int (32 bits --
long ints on linux are 64 bits (on 64 bit systems anyway). I think long ints on windows are 32 bits.)
That doesn't make sense anyway, because 32 bits of randomness should be enough
for
return ((random() & 0x0000ffff) * n) >> 16;
to return something other than 2 rather more often than never, and this code works on 32-bit linux systems on which a "long int" is 32 bits.
Puzzling.
-- steve