.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Half-Life 1 SDK (http://forums.bots-united.com/forumdisplay.php?f=33)
-   -   botmaaaaaaaaan!!!!! (http://forums.bots-united.com/showthread.php?t=1141)

Pierre-Marie Baty 20-03-2004 22:23

botmaaaaaaaaan!!!!!
 
O knowledgeable guru, I need thy immense wisdom again...

... and especially your ability to check one thing or two in the Half-Life source code, if you don't mind :)

I've f*ckedup a metamod plugin, but completely, and as usuals I didn't make backups. That's because the error only occurs on some situations and I never noticed it before. But it's very reproductible indeed: the plugin is Count Floyd's POD-bot, and the crash occurs randomly although very often, only on "cs_" maps, i.e, maps with hostages. The error I get is:

NUM_FOR_EDICT: bad pointer.

Does this sound familiar to you ??
I scoured the source code again and again to no avail. I'm becoming desperate as I need this stupid error to be fixed quickly in order to make a release of this bot and move on to other things (mine, and the united bot thingy). And where I enrage is when I see that the engine exits gracefully with a nice MessageBox, and who says messagebox says no real crash, and who says no crash says NO BREAK IN THE FRIKKIN DEBUGGER !!! I don't give a foack about message boxes, I ONLY WISHED MY DEBUGGER WOULD KICK IN RIGHT AT THE ERROR !!!

If (and as I believe) that's impossible, could you have a look in the engine source code and tell me where are the main places where this error can occur ? I assume the bot is calling an engine function with a fucked parameter, but if I could narrow down my search and avoid checking one after the other the 5,000 engine function calls there are in this stupid bot source code I would be quite pleased. What does this error mean ? I thought it was related to INDEXENT() and ENTINDEX() where you would for example ask the engine for a pointer to an edict_t by number, and passing a number out of range, but I've quintuple-checked these two everywhere I could find them to no avail.

I'm clueless ! What does this error mean ? In which engine function(s) does it kick in ? Please don't tell me "everywhere", I would go mad, please :'(

Lazy 20-03-2004 22:41

Re: botmaaaaaaaaan!!!!!
 
Try looking in the quake 1 source code, I did a quick google for NUM_FOR_EDICT and a few quake source files turned up.

[ Added ]

From looking around in the quake source, it looks like it is used by ENTINDEX( edict_t* ).
Everywhere I have looked so far uses NUM_FOR_EDICT to get the index of an entity, still looking though.

Pierre-Marie Baty 21-03-2004 01:42

Re: botmaaaaaaaaan!!!!!
 
bah don't worry, I made a great fuss again for not very much ----> it's FIXED. w00h00h000000t!!!

Actually I spent hours on it, but the only method that works when all the other fails remain the trial and error: you comment out (/* like this */) half of the code, then compile the bot and see if it crashes. If it doesn't you uncomment half of what you'd commented and you try again. If it doesn't you uncomment half of it again, until you narrow down the bug. :)

The line that was causing the error was, believe it or not:
Code:

pPlayer = ThreatTab[i].pEntity;
pPlayer being edict_t *, pEntity idem, and i being NOT out of range. A perfectly valid line. Everything that was below that line was commented, but IF that line was NOT commented, the game crashed. Unbearable.

Anyhow I put it back because I've found the REAL problem elsewhere in this very function. Count Floyd has the very bad habit of declaring his variable names everywhere BUT where they should be declared.
Code:

void SomeFunction (edict_t *pPlayer) // first definition of pPlayer
{
  int i; // first definition of i
 
  for (i = 0; i < somevalue; i++)
  {
          DoSomething ();
 
          edict_t *pPlayer = INDEXENT (i); // new definition of pPlayer
 
          // three pages later...
 
          for (int index = 0; index < 32; index++)
          {
                // four other pages later...
 
                int i = someOtherValue; // new definition of i
                while (i > 0)
                {
                        edict_t *pPlayer = bots[i].pEdict; // new definition of pPlayer
                        DoSomeStuffWithVariable (i--);
                }
          }
  }
}

there are things like that everywhere. Actually it's a miracle his bot worked so well for all that time... 9_9


Anyway I'm still interested in knowing what the NUM_FOR_EDICT(): bad pointer error means :)

Lazy 21-03-2004 02:00

Re: botmaaaaaaaaan!!!!!
 
Code:

int NUM_FOR_EDICT(edict_t *e)
{
 int  b;
 
 b = (byte *)e - (byte *)sv.edicts;
 b = b / pr_edict_size;
 
 if (b < 0 || b >= sv.num_edicts)
  SV_Error ("NUM_FOR_EDICT: bad pointer");
 return b;
}



Looks like the error is made when the entity index is below zero or greater than the amount of entities in the game.



All times are GMT +2. The time now is 12:10.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.