← Back to team overview

yade-dev team mailing list archive

Re: ScGeom6D crasher

 


Not sure it needs a 3rd common function actually. It should be enough to call new<ScGeom6D> in ScGeom6D::go when needed, then apply ScGeom::go on the interaction, safely casting ScGeom6D to ScGeom3D . So new<> would never be called from inside the 3D version.
Bad idea, the distance would be checked twice.
Another option would be a constructor ScGeom6D(ScGeom&), then replace i->geom with the 6D object in ScGeom6D.
Still two allocations when only one is needed... does it penalize much?
Sounds like I'm back to the 3rd function style. :P

B.


I'll think about it.

B.


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
________________




References