A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Carli » Sat Feb 27, 2010 2:10 pm
I have an other problem:
NewtonCreateCompoundCollision crashes when i want to put some ConvexHulls into it.
I'm using Linux64 and Freepascal.
- Code: Select all
type
TCollisioninfo = array of array of TVec3;
TCollisioninfos = array of record col: TCollisioninfo; pos: TVec3; end;
procedure TLogicEngine.CreatePhysicVoxelMap;
var col: TCollisioninfos;
col2: array of PNewtonCollision;
col3: PNewtonCollision;
bod: PNewtonBody;
mat: TMatrix4;
i, j: integer;
begin
mat:=IdentityMatrix;
col:=graphic.map.exportcollision;
for i:=0 to high(col) do begin
if length(col[i].col)<>0 then begin
mat[3][0]:=col[i].pos[0];
mat[3][1]:=col[i].pos[1];
mat[3][2]:=col[i].pos[2];
setlength(col2,length(col[i].col));
for j:=0 to high(col2) do begin
col2[j]:=NewtonCreateConvexHull(world, length(col[i].col[j]), @col[i].col[j][0], sizeof(TVec3), 0.1, 0, @IdentityMatrix);
end;
col3:=NewtonCreateCompoundCollision(world, length(col2), col2, 0);
bod:=NewtonCreateBody(world, col3);
NewtonBodySetMatrix(bod, @mat[0][0]);
end;
end;
end;
Without binding the Convex Hulls to Compounds, it works fine. But with creating a compound collision, I get a SIGSEGV error.
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Julio Jerez » Sat Feb 27, 2010 3:16 pm
it should not crash.
The only thing I can see tah coudl be a problem is the you do no check if teh conve genereate a shape
- Code: Select all
col2[j]:=NewtonCreateConvexHull(world, length(col[i].col[j]), @col[i].col[j][0], sizeof(TVec3), 0.1, 0, @IdentityMatrix);
end;
if should do:
- Code: Select all
shape = NewtonCreateConvexHull(world, length(col[i].col[j]), @col[i].col[j][0], sizeof(TVec3), 0.1, 0, @IdentityMatrix);
end;
if (shape)
col2[j]:=NewtonCreateConvexHull(world, length(col[i].col[j]), @col[i].col[j][0], sizeof(TVec3), 0.1, 0, @IdentityMatrix);
NewtonCreateConvexHull is the only shape that can return NULL, and this is because if the points do not form a convex hull then it is not possible to make a convex collssion shape.
It is hard to see the code you posted.
if you have a exe that I can test, I can check it out.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Carli » Sun Feb 28, 2010 5:35 pm
AAh solved!!
the pascal headers had a bug:
@Pascal Header: There should be some changes:
- Code: Select all
type
PPNewtonCollision = ^PNewtonCollision;
function NewtonCreateCompoundCollision( const newtonWorld : PNewtonWorld; count : int;
const collisionPrimitiveArray : PPNewtonCollision; shapeID : Int ) : PNewtonCollision; cdecl; external{$IFDEF __GPC__}name 'NewtonCreateCompoundCollision'{$ELSE}NewtonDLL{$ENDIF __GPC__};
Freepascal has an other internal representation of a dynamic array.
PPNewtonCollision should be the right datatype for the collisionPrimitiveArray.
thx for your effort
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Julio Jerez » Sun Feb 28, 2010 5:48 pm
Ha, glad you figured it out.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Carli » Sun Feb 28, 2010 6:03 pm
yes, it would have been an odyssee when you would have started debugging
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by JernejL » Sun Feb 28, 2010 6:51 pm
I don't understand.. i use this:
- Code: Select all
type
PNewtonCollision = ^Pointer;
function NewtonCreateCompoundCollision (const newtonWorld: PNewtonWorld; count: integer; const collisionPrimitiveArray: array of PNewtonCollision; shapeid: integer): PNewtonCollision; cdecl; external newtondll;
And this works fine with freepascal (in delphi compatibility mode ofcourse)
Whose header did you use? there's.. i think 3 pascal headers for 2.0 floating around.
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Stucuk » Mon Mar 01, 2010 8:46 am
@Carli: Why would that make any difference? ^Pointer is still a Pointer. Also the "Official" headers(Ones found in the 2.0 Header thread) have that in them already (With NICE_CODE_PARAMS defined, tho its defined by default).
- Code: Select all
{$IFDEF NICE_CODE_PARAMS}
PNewtonMesh = ^Pointer;
PNewtonBody = ^Pointer;
PNewtonWorld = ^Pointer;
PNewtonJoint = ^Pointer;
PNewtonContact = ^Pointer;
PNewtonMaterial = ^Pointer;
PNewtonCollision = ^Pointer;
PNewtonSceneProxy = ^Pointer;
PNewtonBreakableComponentMesh = ^Pointer;
// JointLibrary
PNewtonUserJoint = ^Pointer;
//PNewtonRagDoll = ^Pointer;
//PNewtonRagDollBone = ^Pointer;
{$ELSE}
They also have it as an array:
- Code: Select all
type
TCollisionPrimitiveArray = array of PNewtonCollision;
function NewtonCreateCompoundCollision( const newtonWorld : PNewtonWorld; count : int;
const collisionPrimitiveArray : TcollisionPrimitiveArray; shapeID : Int ) : PNewtonCollision; cdecl; external{$IFDEF __GPC__}name 'NewtonCreateCompoundCollision'{$ELSE}NewtonDLL{$ENDIF __GPC__};
i think 3 pascal headers for 2.0 floating around.
@Delfi: I thought there was only yours and the one that is a descendent of the 1.53 one (One i did).
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by JernejL » Mon Mar 01, 2010 9:35 am
There's my header (which was built based on ancient sury's header and even predates newton 1.53

)
And then there is yours, and i think sascha also made one on his own, or am i mistaken?
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Dave Gravel » Mon Mar 01, 2010 10:31 am
I have one too, but where is the importance to know about it ?
All is the same if they is up-to-date with last newton version.
-

Dave Gravel
-
- Posts: 801
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Carli » Mon Mar 01, 2010 10:41 am
I'm using mode objfpc, maybe this has an other internal structure of a dynamic array.
The lines are my working lines.
The lines in the official header crashed on Win/linux with FPC
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Dave Gravel » Mon Mar 01, 2010 10:55 am
Maybe you need to disable FPU EX with FPC, no idea it's just a suggestion.
- Code: Select all
initialization
{$IFDEF CPU386}
Set8087CW($133F);
{$ENDIF}
-

Dave Gravel
-
- Posts: 801
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Stucuk » Mon Mar 01, 2010 11:35 am
Delfi wrote:And then there is yours, and i think sascha also made one on his own, or am i mistaken?
Sascha's are a continuation of mine. Tho he merged the 2 separate units into 1. His is the latest version of it.
Dave Gravel wrote:All is the same if they is up-to-date with last newton version.
Thats why it would be great if there was just one, it would have more users checking for changes/mistakes.
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by Carli » Mon Mar 01, 2010 1:45 pm
Maybe we could set the current header into a repository for that everyone can add fixes or updates and I even can have the latest version of it as a subrepos of my project. (i'm using mercurial hg version control)
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by JernejL » Mon Mar 01, 2010 1:50 pm
Dave Gravel wrote:Maybe you need to disable FPU EX with FPC, no idea it's just a suggestion.
- Code: Select all
initialization
{$IFDEF CPU386}
Set8087CW($133F);
{$ENDIF}
Actually, that won't work you need to use Math.SetExceptionMask in fpc! use this instead:
- Code: Select all
{$ifdef fpc}
Math.SetExceptionMask([exInvalidOp,exDenormalized,exZeroDivide,exOverflow,exUnderflow,exPrecision]);
{$else}
Set8087CW($133F); // opengl delphi default!
{$endif}
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 0 guests