CVS UNSTABLE commit (previously known as: [ODE] dRandInt Crash Fix)

Tanguy Fautre tanguy.fautre at spaceapplications.com
Wed Jun 22 12:03:49 MST 2005


I've just commited the implementation from the "May" post into the 
UNSTABLE branch. Although, I did not use the inline version to avoid 
some troubles.

http://q12.org/pipermail/ode-cvs/2005-June/000192.html

Tanguy


Jaroslav Sinecky wrote:
> Good job! These bugs that only appear once after 8 hours are really
> difficult to debug ;)
> 
> I think there was someone on the list saying that he modified dRandInt to
> use only integer aritmetics and worked fine even with quite a gain in
> performance
> ... oh yes, I found it: http://q12.org/pipermail/ode/2005-May/015834.html
> 
> Jaroslav
> 
> 
> -----Original Message-----
> From: ode-bounces at q12.org [mailto:ode-bounces at q12.org]On Behalf Of Colin
> Bonstead
> Sent: Tuesday, June 21, 2005 11:05 PM
> To: ode at q12.org
> Subject: [ODE] dRandInt Crash Fix
> 
> 
> I recently fixed a crash in our game that was occurring in the ODE step.
> The crash typically only happened after the game had been sitting around
> running for 8 hours or so, but a few times it happened in less time than
> that.  It would blow up soon after the joints array was randomized
> during the step.  It turns out that somehow dRandInt was returning a
> number one greater than n, which caused the joint randomization to put
> an invalid pointer in the joint array.
> 
> I'm not sure how that could happen, but at this point I don't really
> have time to investigate it any further, just getting it fixed is more
> important.  Frankly, I'm not quite sure why dRandInt even needs to use
> doubles.  Wouldn't just doing dRand() % n give you a number between 0
> and n?  Regardless, here's a fixed version of dRandInt:
> 
> int dRandInt (int n)
> {
>   double a = double(n) / 4294967296.0;
>   int ret = (int) (double(dRand()) * a);
>   if (ret >= n)
> 	  ret = n-1;
>   return ret;
> }
> 
> 


More information about the ODE mailing list