[ODE] Problem with the colliders table initialisation order with user define geoms.
Sébastien Duval
sebastien.duval at insanelogics.com
Tue Jun 17 11:57:01 2003
This is a multi-part message in MIME format.
------=_NextPart_000_0012_01C334E0.C5486300
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I encountered a problem with the colliders table initialisation combine =
with a user define geom.
This table is declared in collision_kernel.cpp and used as a cache of =
collide function pointers.These function pointers are resolved using a =
selector function (typedef dColliderFn * dGetColliderFnFn (int num);) =
and then cached in the table for future use.
Anyway, this table is initialised (all entry set to NULL) when the first =
geom is created by calling the function initColliders() in the dxGeom =
constructor.
The problem comes if a user define type (geom) is defined. The =
dCreateGeomClass(const dGeomClass *c) must be called to add pointers on =
the dCollideUserGeomWithGeom function (this function may later be called =
to call the selector functions) in the table. At this point, the table =
might not have been initialised.
The problem is that before creating an instance of a geom, its class =
must be created. When the first geom instance is created all changes to =
the table will be wipeout because the table is initialised.
The problem is encountered only when the first geom to be created is a =
user defined one, because the method initColliders() (of course) init =
the table with known types. =20
Anyway, I propose to add a call to initColliders() in the =
dCreateGeomClass function:
int dCreateGeomClass (const dGeomClass *c)
{
dUASSERT(c && c->bytes >=3D 0 && c->collider && c->aabb,"bad geom =
class");
if (num_user_classes >=3D dMaxUserClasses) {
dDebug (0,"too many user classes, you must increase the limit and "
"recompile ODE");
}
user_classes[num_user_classes] =3D *c;
int class_number =3D num_user_classes + dFirstUserClass;
// Make sure the collider table has been initialized.
initColliders();
setAllColliders (class_number,&dCollideUserGeomWithGeom);
num_user_classes++;
return class_number;
}
------=_NextPart_000_0012_01C334E0.C5486300
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I encountered a problem with the =
colliders table=20
initialisation combine with a user define geom.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>This table is declared in =
collision_kernel.cpp and=20
used as a cache of collide function pointers.</FONT><FONT face=3DArial=20
size=3D2>These function pointers are resolved using a selector function =
(<FONT=20
size=3D3><FONT size=3D2>typedef dColliderFn * dGetColliderFnFn (int =
num);) and then=20
cached in the table for future use.</FONT></FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT size=3D3><FONT=20
size=3D2></FONT></FONT></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><FONT size=3D3><FONT size=3D2>Anyway, =
this table is=20
initialised (all entry set to NULL) when the first geom is =
created by=20
calling the function initColliders() in the dxGeom=20
constructor.</FONT></FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT size=3D3><FONT=20
size=3D2></FONT></FONT></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><FONT size=3D3><FONT size=3D2>The=20
problem comes if a user define type (geom) is defined. =
The=20
dCreateGeomClass(const dGeomClass *c) must be =
called to add=20
pointers on the dCollideUserGeomWithGeom function (this =
function=20
may later be called to call the selector functions) in the =
table. At=20
this point, the table might not have been=20
initialised.</FONT></FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT size=3D3><FONT=20
size=3D2></FONT></FONT></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><FONT size=3D3><FONT size=3D2>The =
problem is that=20
before creating an instance of a geom, its class must be created.=20
</FONT></FONT></FONT><FONT face=3DArial size=3D2><FONT size=3D3><FONT =
size=3D2>When the=20
first geom instance is created all changes to the table will =
be=20
wipeout because the table is initialised.</FONT></FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>The problem is encountered =
only when the first=20
geom to be created is a user defined one, because the method =
initColliders() (of=20
course) init the table with known types. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Anyway, I propose to add a call to =
initColliders() in the dCreateGeomClass function:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>int dCreateGeomClass (const dGeomClass=20
*c)<BR>{<BR> dUASSERT(c && c->bytes >=3D 0 =
&&=20
c->collider && c->aabb,"bad geom class");</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> if (num_user_classes >=3D =
dMaxUserClasses)=20
{<BR> dDebug (0,"too many user classes, you must =
increase the=20
limit and "<BR> "recompile =
ODE");<BR> =20
}<BR> user_classes[num_user_classes] =3D *c;<BR> int =
class_number =3D=20
num_user_classes + dFirstUserClass;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> // Make sure the collider table =
has been=20
initialized.<BR> initColliders();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> setAllColliders=20
(class_number,&dCollideUserGeomWithGeom);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> num_user_classes++;<BR> =
return=20
class_number;<BR>}<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT><FONT face=3DArial=20
size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial><BR><FONT =
size=3D2></FONT></FONT></DIV></FONT></BODY></HTML>
------=_NextPart_000_0012_01C334E0.C5486300--