← Back to team overview

yade-dev team mailing list archive

Re: ScGeom6D crasher

 

Oh, yes, you are right. Initially, I put all code in a third function that was called from both go(), but it was more compact with the current style - and I didn't realize the obvious allocation problem. Feel free to fix that, if you don't I'll do it a.s.a.p (i.e. tomorrow maybe).
Now the question is : why does it work?!!

Bruno



On 26/10/10 17:26, Chiara + Václav wrote:
Hi Bruno,

we were just reading the ScGeom6D code and there a serious bug. Suppose
a potential interaction of 2 spheres; Ig2_Sphere_Sphere_ScGeom6D::go
calls Ig2_Sphere_Sphere_ScGeom::go, which, if it succeeds, creates a new
ScGeom object and assigns it to I->geom. Then the execution goes back to
Ig2_Sphere_Sphere_ScGeom6D::go, which will cast I->geom to ScGeom6D!
This is not a valid operation and if you run in debug mode, the
YADE_PTR_CAST will return NULL pointer. (

If you want to avoid code duplication, the common function must know
what IGeom object to create, via a function argument; and since one
cannot change the signature of ::go (otherwise the virtual call would
call a different function), the common functionality must be in a
separate function called from both ::go functors, but with different
parameters.

You can have a look at Ig2_Sphere_Sphere_L3Geom and
Ig2_Sphere_Sphere_L6Geom for inspiration.

Cheers, cv




_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to     : yade-dev@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp



--
_______________
Bruno Chareyre
Associate Professor
ENSE³ - Grenoble INP
Lab. 3SR
BP 53 - 38041, Grenoble cedex 9 - France
Tél : +33 4 56 52 86 21
Fax : +33 4 76 82 70 43
________________




Follow ups

References