Is there a reason why Collisions belong to a World?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Is there a reason why Collisions belong to a World?

Postby Marc » Wed Aug 19, 2009 2:05 pm

Hi !

In my game, I have multiple NewtonWorlds at the same time. Several equal Collisions exist in multiple worlds. Yet I have to create them for every world itself. For normal collisions this is no big problem, but some collisions like Tree- and the new SceneCollision have an Optimze call which takes some time to calculate. So would it be possible to have collision construction and destruction seperated from worlds? Or is there a reason it is like that?

Just a thought: Theoretically, one could do that already by creating a newton world with the collisions and linking that collision to the main newton world by a usercollision. That way one can create multiple worlds using that collision and only optimizing it once.

Marc
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Is there a reason why Collisions belong to a World?

Postby Julio Jerez » Wed Aug 19, 2009 2:18 pm

if you call MakeUnique after creation, the collision will be removed from the world, But you will have to take care of caching.
you have lot of elipoid that are cached, it made lead to lot of memory usage.

I beleive some collision do have a pointer to the world I am no sure.
I know that the Compound collisions for some reason has themn i hae to check out.

tecnically it is a s simple as calling MakeUnique. and you can re use collision shapes in separated worlds.
you can try that and see how is goes.

But maybe it is better to wait for 2.08 before you try the Scene CollisionShape.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Is there a reason why Collisions belong to a World?

Postby Marc » Wed Aug 19, 2009 2:36 pm

Ok so if I understand correctly, I create a seperate NewtonWorld where I create my optimized collisions in, call MakeUnique, then use them in whatever world I want and at the very end I call NewtonReleaseCollision with that collision and that seperate NewtonWorld?

Yeah I'm not changing that physics stuff before you release your new version - otherwise, if something suddenly behaves odd, I don't know if it's related to my changes or yours. Single point of failure ... ;)
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Is there a reason why Collisions belong to a World?

Postby Julio Jerez » Wed Aug 19, 2009 2:52 pm

Marc wrote:Ok so if I understand correctly, I create a seperate NewtonWorld where I create my optimized collisions in, call MakeUnique, then use them in whatever world I want and at the very end I call NewtonReleaseCollision with that collision and that seperate NewtonWorld?


you do not need to create a world jut for making shapes, any world is good, and sence you are detaching the shapes from the world,
then It does not matter what world you use to release then, the shape will not be in the list of collision that world owns,
it will simply reduce the ref count and if it reach zero the destrutor will be called on teh shape.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Is there a reason why Collisions belong to a World?

Postby Marc » Wed Aug 19, 2009 3:21 pm

ok :)
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Is there a reason why Collisions belong to a World?

Postby Marc » Wed Nov 18, 2009 10:00 pm

Related to this thread http://newtondynamics.com/forum/viewtopic.php?f=12&t=5518, I tried replacing opcode-usercollision by newtontrianglecollisions.

Because I have multiple newtonworlds at the same time that contain rougly the same collisions, I tried this. Unless I did something terribly wrong, I get "Pure Virtual Function call" just somewhere in my code now, no stacktrace nothing. I have no idea what that causes yet. If that doesn't happen, it crashed on NewtonDestroyBody. What I excctly do is this:

- I create a temporary NewtonWorld A
- I deserialize the newtoncollision in world A
- I call makeunique
- I destroy the temporaray Newtonworld A
- I create a new world B
- I create a body that uses the collision
- some time later, I destroy the body - and it crashes:

Code: Select all
    newton.dll!dgWorld::ReleaseCollision(dgCollision * collision=0x03ce9100)  Line 607   C++
    newton.dll!dgWorld::DestroyBody(dgBody * body=0x03f05a00)  Line 560   C++
    newton.dll!NewtonDestroyBody(const NewtonWorld * newtonWorld=0x03e65cc0, const NewtonBody * bodyPtr=0x03f05a00)  Line 4320   C++
>   Node0.exe!CUZMine::DestroyPhys()  Line 153 + 0x1f bytes   C++
    Node0.exe!CUPhysics::DestroyAllObjectsPhys()  Line 274 + 0xf bytes   C++
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Is there a reason why Collisions belong to a World?

Postby Marc » Wed Nov 18, 2009 10:03 pm

heh, because of your disassembly request from the other thread and beacuse the debugger is still open at that crash, I just post the disasm of this as well

the yellow arrow points at

0019CB2E mov eax,dword ptr [ebx]


Code: Select all
--- c:\newton_200\3dlib\sdk\physics\dgnarrowphasecollision.cpp -----------------
0019CAB0  push        esi 
0019CAB1  push        edi 
0019CAB2  mov         edi,ecx
0019CAB4  mov         esi,dword ptr [edi+4FCh]
0019CABA  mov         ecx,dword ptr [esp+0Ch]
0019CABE  mov         edx,dword ptr [ecx+5Ch]
0019CAC1  test        esi,esi
0019CAC3  je          dgWorld::RemoveFromCache+4Dh (19CAFDh)
0019CAC5  mov         eax,dword ptr [esi+14h]
0019CAC8  cmp         edx,eax
0019CACA  jae         dgWorld::RemoveFromCache+20h (19CAD0h)
0019CACC  mov         esi,dword ptr [esi]
0019CACE  jmp         dgWorld::RemoveFromCache+25h (19CAD5h)
0019CAD0  jbe         dgWorld::RemoveFromCache+2Eh (19CADEh)
0019CAD2  mov         esi,dword ptr [esi+4]
0019CAD5  test        esi,esi
0019CAD7  jne         dgWorld::RemoveFromCache+15h (19CAC5h)
0019CAD9  pop         edi 
0019CADA  pop         esi 
0019CADB  ret         4   
0019CADE  test        esi,esi
0019CAE0  je          dgWorld::RemoveFromCache+4Dh (19CAFDh)
0019CAE2  mov         eax,dword ptr [ecx]
0019CAE4  mov         edx,dword ptr [eax+60h]
0019CAE7  call        edx 
0019CAE9  dec         dword ptr [edi+4F8h]
0019CAEF  add         edi,4FCh
0019CAF5  push        edi 
0019CAF6  mov         ecx,esi
0019CAF8  call        dgRedBackNode::Remove (1EEA90h)
0019CAFD  pop         edi 
0019CAFE  pop         esi 
0019CAFF  ret         4   
--- No source file -------------------------------------------------------------
0019CB02  int         3   
0019CB03  int         3   
0019CB04  int         3   
0019CB05  int         3   
0019CB06  int         3   
0019CB07  int         3   
0019CB08  int         3   
0019CB09  int         3   
0019CB0A  int         3   
0019CB0B  int         3   
0019CB0C  int         3   
0019CB0D  int         3   
0019CB0E  int         3   
0019CB0F  int         3   
--- c:\newton_200\3dlib\sdk\physics\dgnarrowphasecollision.cpp -----------------
0019CB10  push        ebx 
0019CB11  mov         ebx,dword ptr [esp+8]
0019CB15  push        edi 
0019CB16  mov         edi,ecx
0019CB18  mov         eax,dword ptr [edi+714h]
0019CB1E  test        eax,eax
0019CB20  je          dgWorld::ReleaseCollision+1Eh (19CB2Eh)
0019CB22  cmp         dword ptr [ebx+54h],1
0019CB26  jne         dgWorld::ReleaseCollision+1Eh (19CB2Eh)
0019CB28  push        ebx 
0019CB29  call        eax 
0019CB2B  add         esp,4
0019CB2E  mov         eax,dword ptr [ebx]
0019CB30  mov         edx,dword ptr [eax+60h]
0019CB33  mov         ecx,ebx
0019CB35  call        edx 
0019CB37  cmp         eax,1
0019CB3A  jne         dgWorld::ReleaseCollision+8Ch (19CB9Ch)
0019CB3C  mov         ecx,dword ptr [ebx+5Ch]
0019CB3F  push        esi 
0019CB40  mov         esi,dword ptr [edi+4FCh]
0019CB46  test        esi,esi
0019CB48  je          dgWorld::ReleaseCollision+8Bh (19CB9Bh)
0019CB4A  lea         ebx,[ebx]
0019CB50  mov         eax,dword ptr [esi+14h]
0019CB53  cmp         ecx,eax
0019CB55  jae         dgWorld::ReleaseCollision+4Bh (19CB5Bh)
0019CB57  mov         esi,dword ptr [esi]
0019CB59  jmp         dgWorld::ReleaseCollision+50h (19CB60h)
0019CB5B  jbe         dgWorld::ReleaseCollision+5Ah (19CB6Ah)
0019CB5D  mov         esi,dword ptr [esi+4]
0019CB60  test        esi,esi
0019CB62  jne         dgWorld::ReleaseCollision+40h (19CB50h)
0019CB64  pop         esi 
0019CB65  pop         edi 
0019CB66  pop         ebx 
0019CB67  ret         4   
0019CB6A  test        esi,esi
0019CB6C  je          dgWorld::ReleaseCollision+8Bh (19CB9Bh)
0019CB6E  mov         eax,dword ptr [edi+714h]
0019CB74  test        eax,eax
0019CB76  je          dgWorld::ReleaseCollision+6Eh (19CB7Eh)
0019CB78  push        ebx 
0019CB79  call        eax 
0019CB7B  add         esp,4
0019CB7E  mov         eax,dword ptr [ebx]
0019CB80  mov         edx,dword ptr [eax+60h]
0019CB83  mov         ecx,ebx
0019CB85  call        edx 
0019CB87  dec         dword ptr [edi+4F8h]
0019CB8D  add         edi,4FCh
0019CB93  push        edi 
0019CB94  mov         ecx,esi
0019CB96  call        dgRedBackNode::Remove (1EEA90h)
0019CB9B  pop         esi 
0019CB9C  pop         edi 
0019CB9D  pop         ebx 
0019CB9E  ret         4   
--- No source file -------------------------------------------------------------
0019CBA1  int         3   
0019CBA2  int         3   
0019CBA3  int         3   
0019CBA4  int         3   
0019CBA5  int         3   
0019CBA6  int         3   
0019CBA7  int         3   
0019CBA8  int         3   
0019CBA9  int         3   
0019CBAA  int         3   
0019CBAB  int         3   
0019CBAC  int         3   
0019CBAD  int         3   
0019CBAE  int         3   
0019CBAF  int         3   
--- c:\newton_200\3dlib\sdk\physics\dgnarrowphasecollision.cpp -----------------
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Is there a reason why Collisions belong to a World?

Postby Stucuk » Wed Nov 18, 2009 11:02 pm

Pure Virtual Function call means that you have code which is calling a class that has a virtual procedure/function which isn't being overridden with an actual valid procedure/function.

Example(I know its in delphi, but should be easy enough to understand):
Code: Select all
TParentClass = Class(TObject)
public
procedure MyVirtualProc; virtual; abstract;
end;

TChildClass = Class(TParentClass)
public
 // Doesn't contain a MyVirtualProc override
end;
-------------------------

procedure Whatever;
var
 MyClass : TChildClass;
begin
 MyClass.MyVirtualProc; // Error
end;
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: Is there a reason why Collisions belong to a World?

Postby Marc » Wed Nov 18, 2009 11:11 pm

I know, I'm just wondering why it doesn't break in the debugger and shows me the stacktrace. Instead I only get a msgbox telling me about the pure virtual function call with an ok button and that's it. Clicking it stops the process and vs gets back into editor mode :/
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Is there a reason why Collisions belong to a World?

Postby Stucuk » Thu Nov 19, 2009 10:05 am

I assume because its the VC Runtime * thats generating the error message instead of the application its self. Tho im just guessing.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: Is there a reason why Collisions belong to a World?

Postby Marc » Thu Nov 19, 2009 7:26 pm

Huh, I just forgot the remove some NewtonCollisionRelease after creating the bodies. Since I don't create them for every body anymore I should release them as well. :/

As far as I can tell, it's working like it's supposed to now - no crashes anymore :)
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests