Server Help

ASSS Questions - A hidden bug in my module

gilder - Fri Dec 08, 2006 1:20 pm
Post subject: A hidden bug in my module
I have been trying to fix this bug for a few days now and I just can't find it. The code is about 650 rows long so I don't know if anyone is willing to help. I'll try to explain my problem as well as I can.

When I enter commando arena, go in, right and enter the commando region, bots will appear. When I spec, while bots are still in, and enter again, zone crashes. Bots will appear before I even can get in and server acts like I was in warbird. If I leave the arena and come back, I can enter again without crashing my zone.

To give you better idea what's going on, I put level file, arena.conf, dll and .c file in this zip.

Thanks
Cyan~Fire - Sat Dec 09, 2006 11:51 am
Post subject:
Looking at it... I'll edit this post if I find anything.

Code: Show/Hide
const char tracknames[TRACKS][10];

I don't think this is related to your bug, but I believe the [TRACKS] and [10] should be reversed. (And store this in a linked-list or something dynamically-sized anyway for goodness sake.)

Not a bug, just a suggestion for less typing (and better reliability):
Code: Show/Hide
            strcpy(str, "Track");
            strcat(str, myitoa(i+1));
            strcat(str, "Name"); 
could and should be
Code: Show/Hide
            _snprintf(str, sizeof(str), "Track%dName", i+1);

gilder - Sat Dec 09, 2006 3:50 pm
Post subject:
Thanks for your time.

I started to work with this project more and now it doesn't crash when i spec and re-enter, and i have no idea why.. May be even a small conf value change. Who knows.
Smong - Sun Dec 10, 2006 12:36 pm
Post subject:
md->FindRegionByName(arena, tracknames[i]) can fail, you should check whether what it returns is NULL or not, also tracknames[i] may be unset depending on what's in your conf.

game->SetFreqAndShip(), if you aren't changing the freq just use SetShip().

Unpacking settings: (Track#Bot#Point#: coordinates are in pixels)
Code: Show/Hide
   char buf[64];
   const char *s;
   int a, b;

   snprintf(buf, sizeof(buf), "Track%dBot%dPoint%d", event+1, part+1, point+1);

   s = cfg->GetStr(arena->cfg, "Commando", buf);
   if (s)
   {
      a = b = 0;
      sscanf(s, "%d , %d", &a, &b);
      *x = a;
      *y = b;
   }


If you enable compiler warnings (such as -Wall in gcc) it will tell you myitoa() is returning an address to a local variable. If you read the settings how I demonstrated above you can get rid of the myitoa function.

As for the crashing problem, it did happen to me too. But then it kinda stopped, so it may be something to do with reading from unitialised memory.
Cyan~Fire - Sun Dec 10, 2006 1:43 pm
Post subject:
Ooh, I didn't even catch that bug with myitoa(). So that was actually a bug, not just a suggestion. icon_smile.gif
Smong - Sun Dec 10, 2006 5:26 pm
Post subject:
Also "const char tracknames[TRACKS][10]" shouldn't be reversed, but you need to remove the const keyword. I also notice some other place in your code you put Botdata instead of BotData, not sure what compiler you are using but I can't imagine many allowing that.
Cyan~Fire - Sun Dec 10, 2006 9:34 pm
Post subject:
Smong's right about the reversing, my bad.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group