NewtonBodyTransformCallback problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonBodyTransformCallback problem

Postby Henry00 » Mon Aug 01, 2011 7:35 pm

Hi everyone, I am currently writing an engine with the team 00Laboratories, you can see some shots here: http://henry00.ftpaccess.cc/henry00/projects/

I am currently trying to add some physics, the engine is written in Purebasic and I have a very annoying issue, NewtonBodyTransformCallback procedure gets called completly, it ends and then it crashes, I have no idea why it happends, all the values in the debugger look perfect!

Code: Select all
Procedure physics_NewtonBodyTransformCallback(*body, *matrix, threadIndex.i)
   ; Get the position from the matrix
   Dim test.f(15)
   NewtonBodyGetMatrix(*body, @test())
   *posit.Vector3D = Vector3D(test(12),test(13),test(14))
   
   *rotation.Vector3D = Vector3D(0,0,0)
 
   ; we will ignore the Rotation part of matrix And use the quaternion rotation stored in the body
   NewtonBodyGetRotation(*body, *rotation)
 
   ; get the entity associated With this rigid body
   *ent.gameobject = NewtonBodyGetUserData(*body)
 
   *ent\rotation\x = *rotation\x
   *ent\rotation\y = *rotation\y
   *ent\rotation\z = *rotation\z
   *ent\position\x = *posit\x
   *ent\position\y = *posit\y
   *ent\position\z = *posit\z

   Debug "NEW POSITION:"+Str(*ent\position\x)+","+Str(*ent\position\y)+","+Str(*ent\position\z)
  Debug "A TRANSFORM CALLBACK"
EndProcedure  < - CRASH!!!!!! No idea why, values look fine


Thanks for any help!
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Re: NewtonBodyTransformCallback problem

Postby Julio Jerez » Wed Aug 03, 2011 1:20 pm

maybe Dim test.f(15)
should be Dim test.f(16)

a matrix is 16 floats not 15
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodyTransformCallback problem

Postby Henry00 » Wed Aug 03, 2011 1:33 pm

Hm all the other functions using matrix look happy, I tried it and it didn't work, also from the manual:

When you define a new array, please note that it will have one more element than you used as parameter, because the numbering of the elements in PureBasic (like in other BASIC's) starts at element 0. For example when you define Dim(10) the array will have 11 elements, elements 0 to 10. This behaviour is different for static arrays in structures.
Last edited by Henry00 on Wed Aug 03, 2011 1:46 pm, edited 1 time in total.
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Re: NewtonBodyTransformCallback problem

Postby Julio Jerez » Wed Aug 03, 2011 1:35 pm

0 + 15 = 15 not 16

trust me the array is 15 element not 16.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodyTransformCallback problem

Postby Henry00 » Wed Aug 03, 2011 1:48 pm

Sorry about the edit, I should write it as a reply from now on, still didn't work, strange part is even WITHOUT code it crashes!
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Re: NewtonBodyTransformCallback problem

Postby Henry00 » Wed Aug 03, 2011 1:54 pm

Interesting note to this issue would be, it's our usual error "invalid memory access" but usually it is a read memory error, now it tells me write error at adress ***, maybe it's a flaw in the arguments or something?
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Re: NewtonBodyTransformCallback problem

Postby JoeJ » Wed Aug 03, 2011 2:07 pm

I think it's because NewtonBodyGetRotation(*body, *rotation)
if rotation is a 3 floats vector it will cause a write error because this function expects space for 4 values.
Quaternion = 4 values.
User avatar
JoeJ
 
Posts: 1494
Joined: Tue Dec 21, 2010 6:18 pm

Re: NewtonBodyTransformCallback problem

Postby Henry00 » Wed Aug 03, 2011 2:16 pm

Hm thanks for that 4 values tip, I never heard of the word Quaternion before and couldn't find the right resources for it.
Also to show you the thing as it's happening with no code:

Image
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Re: NewtonBodyTransformCallback problem

Postby JoeJ » Wed Aug 03, 2011 2:24 pm

you commented GetRotation out and it still happens?
... what if you disable the Newton BodyGetMatrix line too?

EDIT: Maybe the user data entity stuff wasn't setup for a single body.
You could check with something like (in C):
*ent.gameobject = NewtonBodyGetUserData(*body)
if (ent.gameobject == 0) // check for zero pointer / uninitialized?
{
breakpoint for debugger here, should never reach this
}
Last edited by JoeJ on Wed Aug 03, 2011 2:44 pm, edited 3 times in total.
User avatar
JoeJ
 
Posts: 1494
Joined: Tue Dec 21, 2010 6:18 pm

Re: NewtonBodyTransformCallback problem

Postby Henry00 » Wed Aug 03, 2011 2:26 pm

JoeJ wrote:you commented GetRotation out and it still happens?
... what if you disable the Newton BodyGetMatrix line too?


I commented everything out, that's the issue, been having this for days, it's so lame I mean objects are falling already, manually updating positions due to this callback giving an error
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Re: NewtonBodyTransformCallback problem

Postby Henry00 » Wed Aug 03, 2011 2:46 pm

OK I NOTICED SOMETHING ELSE!!!
I made another newton object called map, it's a not working yet collision tree, for some reason when I had set mass to none there, the barrel which is supposed to fall down didn't fall anymore... awkward, I set it back and it errors!

Code: Select all
  Dim testmatrix.f(15)
  Global *map_nBody = NewtonCreateBody(*physics_nWorld, *physics_nWorldTree, @testmatrix)
  NewtonBodySetDestructorCallback( *map_nBody, @physics_destroyBodyCallback() )
  NewtonReleaseCollision( *physics_nWorld, *physics_nWorldTree )
  NewtonBodySetMassMatrix(*map_nBody,100, 100, 100, 100)


By setting this one's mass the barrel stops falling... totally different variables

Edit:
Oh right foreachpolygondo if used also crashes at the end of function.

@jouJ, you probably don't see the image? http://henry00.ftpaccess.cc/henry00/pro ... csevil.PNG
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Re: NewtonBodyTransformCallback problem

Postby Julio Jerez » Wed Aug 03, 2011 3:03 pm

a body with zeor mass become static.

if you commnet put the entire body of the callback, does still crashes?
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodyTransformCallback problem

Postby Henry00 » Wed Aug 03, 2011 3:07 pm

Ok if I understood that right.. I commented all the map newton code, but it still crashes, I just noticed by setting the mass over there it changed the wrong newton bodies.. Btw I am a real fan of NewtonGD, awesome work. I commented everything now, this is left of barrel, still crashing:

Code: Select all
  Dim testmatrix.f(15)
  *testcollision = NewtonCreateBox(*physics_nWorld, 5, 5, 5, 0, @testmatrix)
  Global *testbody = NewtonCreateBody(*physics_nWorld, *testcollision, @testmatrix)
  NewtonReleaseCollision(*physics_nWorld, *testcollision)
  NewtonBodySetMassMatrix(*testbody, 10, 5, 5, 5)
  ;NewtonBodySetUserData(*testbody, *obj1)
  NewtonBodySetForceAndTorqueCallback( *testbody, @physics_ApplyForceAndTorqueCallback() )
  NewtonBodySetTransformCallback( *testbody, @physics_NewtonBodyTransformCallback() )
  NewtonBodySetDestructorCallback( *testbody, @physics_destroyBodyCallback() )
Last edited by Henry00 on Wed Aug 03, 2011 3:10 pm, edited 1 time in total.
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Re: NewtonBodyTransformCallback problem

Postby JoeJ » Wed Aug 03, 2011 3:08 pm

The Image is visible in forum, i've edited my last message while you replied.

Dim testmatrix.f(15)
Global *map_nBody = NewtonCreateBody(*physics_nWorld, *physics_nWorldTree, @testmatrix)

... maybe problematic because testmatrix is uninitialized and contains either all zeros or random numbers (depending on how Basic handles this).
Or does it initialize to identity matrix? I've forgotten everything about Basic and can't read the code.
Identity is
1,0,0,0, (rotation x axis,0)
0,1,0,0, (rotation y axis,0)
0,0,1,0, (rotation z axis,0)
0,0,0,1 (position xyz,1)
You know that? If not you need to get some math background first...

And: Setting a bodys mass to zero makes it static / unmoveable.
Last edited by JoeJ on Wed Aug 03, 2011 3:15 pm, edited 1 time in total.
User avatar
JoeJ
 
Posts: 1494
Joined: Tue Dec 21, 2010 6:18 pm

Re: NewtonBodyTransformCallback problem

Postby Henry00 » Wed Aug 03, 2011 3:13 pm

It's all 0, just declaring 16 floats in an array, helpfile:
Dim is used to create new arrays (the initial value of each element will be zero).


And I changed the mass of my TreeCollision newton object for my map, and it affected my barrel object, even though it's totally somewhere else with unique variables.

Here is the matrix you wanted from the 48 lines C tuturial:

Code: Select all
  Dim testmatrix.f(15)
  testmatrix(0) = 1
  testmatrix(1) = 0
  testmatrix(2) = 0
  testmatrix(3) = 0
  testmatrix(4) = 0
  testmatrix(5) = 1
  testmatrix(6) = 0
  testmatrix(7) = 0
  testmatrix(8) = 0
  testmatrix(9) = 0
  testmatrix(10) = 1
  testmatrix(11) = 0
  testmatrix(12) = 0
  testmatrix(13) = 0
  testmatrix(14) = 0
  testmatrix(15) = 1
  *testcollision = NewtonCreateBox(*physics_nWorld, 5, 5, 5, 0, @testmatrix)
  Global *testbody = NewtonCreateBody(*physics_nWorld, *testcollision, @testmatrix)

Sadly it still crashes though :(
00Laboratories
Solutions for Developers
http://00laboratories.com/
Henry00
 
Posts: 37
Joined: Mon Aug 01, 2011 7:29 pm
Location: Germany

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 179 guests