.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

  • View media
  • View media
  • View media
  • View media
  • View media
  • View media
Add media Report RSS BadWolf loop bug (view original)
BadWolf loop bug
embed
share
view previous next
Share Image
Share on Facebook Post Email a friend
Embed Image
Post comment Comments
numbersix Author
numbersix - - 2,244 comments

A nasty bug in quake-c where a sequence of code runs wild. The server has a statement counter and if 10000000 jumps are reached in a certain section of code, it just gives up and displays this.

This case seems to have been caused by findradius.

When you call findradius, it makes a linked list in the ".chain" entity pointer.

So you could code:

local entity e;

e = findradius(self.origin, 1024);

while (e)
{
// some code

e = e.chain;
}

findradius terminates the last .chain with world.
Good enough.

But, if you happen to call findradius while you are in that loop (and you may not realized if it is called by a subroutine) the .chain loop can become infinite.

There are 2 solutions:

1. make sure you dont nest findradius calls
2. put in a loop safety:

local float sf;

sf = 2000;

e = findradius(self.origin, 1024);

while (e && (sf > 0))
{
// some code

sf = sf - 1;
e = e.chain;
}

My code has gotten to the complexity where I always put in a safety counter and code for a fail condition.

Reply Good karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: