Bug in QuadTree space?

30 views
Skip to first unread message
Message has been deleted

Oleh Derevenko

unread,
Jul 7, 2020, 7:42:04 PM7/7/20
to ode-...@googlegroups.com, David Guillen Fandos
-----Original Message-----
From: David Guillen Fandos <da...@davidgf.net>
Sent: Wednesday, July 8, 2020 2:28 AM
To: Oleh Derevenko <od...@eleks.com>
Subject: Bug in QuadTree space?

Hey there!

Since I'm not sure I'm not doing anything wrong I'd figured I'd send you an email before filing a bug :P

The code fails with:

ODE INTERNAL ERROR 2: object is not in this space in remove()

I wrote a minimal test case for you to reproduce, I'm not sure if the test case is "valid".

Thanks a lot for your work in ODE!
David

________________________________

This e-mail may contain privileged and confidential information. If you are not the intended recipient, be aware that any use, disclosure, copying or distribution of this e-mail or any attachments is prohibited. If you have received this e-mail in error, please notify us immediately by returning it to the sender and delete this copy from your system. Thank you.
test.cc

Rodrigo Hernandez

unread,
Jul 8, 2020, 1:55:23 AM7/8/20
to ode-...@googlegroups.com, David Guillen Fandos

Here:

dSpaceRemove(world_space, geom); <------ Removed from world_space
dSpaceAdd(world_space, geom); <------ Added back to world_space

dSpaceRemove(space, geom); // <------ geom was never added to space,
nor was created there
dSpaceAdd(space, geom);


Cheers!

David Guillen Fandos

unread,
Jul 8, 2020, 12:41:53 PM7/8/20
to ode-...@googlegroups.com
Forwarding my next email again now that i've joined the mailing list

David

--
I'm sorry ignore my previous email, I screwed it up trying to reproduce
this. It took me a bit more and confused the error message :P

The error is:
ODE INTERNAL ERROR 2: geom is already in a space in add()

Note that (comments) if I remove some unrelated lines it does work.
Interestingly enough debugging the ASSERT it seems like it's half true,
so I'm suspecting some "next" pointer might not be set to NULL when it
really should.

Thanks!
David
--
test.cc
Message has been deleted

Oleh Derevenko

unread,
Jul 28, 2020, 6:15:05 AM7/28/20
to ode-...@googlegroups.com

Hi David,

 

Sorry, I did not look into your example.

To be honest, I (almost) never look into test cases like these since I have little experience with building ODE object structures and it would require me studying ODE API as well.

 

Why would not you check demo applications included with the library first? Like most of the application libraries, ODE requires initialization and finalization calls (which are missing from your source).

 

Oleh Derevenko

-- Skype with underscore
GPG Key Fingerprint: 2F56 32DC DCD9 B2BB 06E9 39E8 A37E 5E60 376E C691

 

From: ode-...@googlegroups.com <ode-...@googlegroups.com> On Behalf Of David Guillen
Sent: Sunday, July 26, 2020 10:00 PM
To: ode-users <ode-...@googlegroups.com>
Subject: Re: Re: [ode-users] Bug in QuadTree space?

 

Hey there!

Just a ping on this. Oleh: do you think this is a bug or is it "working as intended"?

I'm a bit confused with the API so if you could clarify... I might have some time to debug the issue if you confirm this is non-intended behaviour.

 

Thanks!

openpgp-digital-signature.asc

David Guillen Fandos

unread,
Jul 28, 2020, 12:26:31 PM7/28/20
to ode-...@googlegroups.com
Hey there!

Well most examples only build an scenario and use it. In my case, this comes from an old game I did, I move objects between spaces to optimize the collision routines (so that objects that cannot touch each other are not tested for collision). I think what I'm doing is 100% valid and legit, removing an object and re-adding it back, but for some reason it fails.
My hunch is that the assert fails due to some pointer not being cleared up during the remove routine.

Thanks
David

Oleh Derevenko

unread,
Jul 28, 2020, 1:44:06 PM7/28/20
to ode-...@googlegroups.com

 

#include <ode/ode.h>

 

int main(int argc, char **argv) {

      float t[3] = {0,0,0};

 

      auto world = dWorldCreate();

      dWorldSetQuickStepNumIterations(world, 10);

 

      auto space = dSimpleSpaceCreate(0);

      dReal d[3] = {10, 10, 10};

      auto world_space = dQuadTreeSpaceCreate(space, t, &d[0], 5);

 

      dSpaceID subspace = dSimpleSpaceCreate(space);

      dSpaceID subspace2 = dSimpleSpaceCreate(space);

      dSpaceID subspace3 = dSimpleSpaceCreate(space);

      dSpaceID subspace4 = dSimpleSpaceCreate(world_space);  // Comment out these two lines

      dSpaceID subspace5 = dSimpleSpaceCreate(world_space);  // to make it work

 

      auto body = dBodyCreate(world);

      auto geom = dCreateBox(subspace, 1, 1, 1);

      dMass m;

      dMassSetBox(&m, 1, 1, 1, 1);

      dGeomSetBody(geom, body);

      dGeomSetOffsetPosition (geom, 0, 0, 0);

 

      // Disable

      dSpaceRemove(dGeomGetSpace((dGeomID)subspace), (dGeomID)subspace);

      dSpaceAdd(world_space, (dGeomID)subspace);

 

      // Enable

      dSpaceRemove(dGeomGetSpace((dGeomID)subspace), (dGeomID)subspace);

      dSpaceAdd(space, (dGeomID)subspace);

 

      // Disable

      dSpaceRemove(dGeomGetSpace((dGeomID)subspace), (dGeomID)subspace);

      dSpaceAdd(world_space, (dGeomID)subspace);

}

 

> Like most of the application libraries, ODE requires initialization and finalization calls (which are missing from your source).

This means that you must call the library initialization function, at least, before starting calling other functions and creating objects from it.

 

Generally, it’s always a good idea to look through library public headers before starting writing code that uses it.

 

 

Oleh Derevenko

-- Skype with underscore
GPG Key Fingerprint: 2F56 32DC DCD9 B2BB 06E9 39E8 A37E 5E60 376E C691

 

From: ode-...@googlegroups.com <ode-...@googlegroups.com> On Behalf Of David Guillen Fandos
Sent: Tuesday, July 28, 2020 7:26 PM
To: ode-...@googlegroups.com
Subject: Re: Re: [ode-users] Bug in QuadTree space?

 

Hey there!

 

Well most examples only build an scenario and use it. In my case, this comes from an old game I did, I move objects between spaces to optimize the collision routines (so that objects that cannot touch each other are not tested for collision). I think what I'm doing is 100% valid and legit, removing an object and re-adding it back, but for some reason it fails.

openpgp-digital-signature.asc

David Guillen Fandos

unread,
Jul 28, 2020, 2:04:55 PM7/28/20
to ode-...@googlegroups.com
Hello,

Sorry did not understand what you meant :)

This is a mistake I did when I created this small test case, in my original source there's calls to dInitODE. So adding the init function stills make this crash in the same way.
Also I do not think de-initialization routines are relevant for the bug case, since the program asserts before getting to the end, therefore they would be irrelevant right?

Thanks again!
David
--
You received this message because you are subscribed to a topic in the Google Groups "ode-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ode-users/MpSfjodUWEM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ode-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ode-users/VI1PR0701MB684717C0162C5F5CCA0621A9DD730%40VI1PR0701MB6847.eurprd07.prod.outlook.com.

David Guillen Fandos

unread,
Jul 28, 2020, 2:26:40 PM7/28/20
to ode-...@googlegroups.com
Hey there!

Ok so taking a look back in history, since I know my old code used to work well in an older version of ODE (back in 2012, version 0.11 or so IIRC).
I found a suspicious commit:


Which I do not totally understand, since I cannot find the issues/PRs mentioned there, #151 and #22. I do not understand why we would need an extra pair of pointers for quad spaces instead of using the regular ones. Could you elaborate?

However what's more or less clear to me is that during this fix/migration there was a cleanup step missed along the way that is causing the bug, here's my patch (I'm not 100% sure it works, it does for my case, but I'd need to run more tests to validate it and perhaps understand better what I'm doing):

diff --git a/ode/src/collision_quadtreespace.cpp b/ode/src/collision_quadtreespace.cpp
index 200b20f5..bfd7d284 100644
--- a/ode/src/collision_quadtreespace.cpp
+++ b/ode/src/collision_quadtreespace.cpp
@@ -281,6 +281,7 @@ void Block::DelObject(dGeomID Object){
     }
 
     Object->tome_ex = 0;
+    Object->next_ex = 0;
 
     // Now traverse upwards to tell that we have lost a geom
     Block* Block = this;


I think remove() in space does that as cleanup, to ensure the geom pointers are zeroed-out, but in quadspace the extra pointers seem to be missing the next pointer to be cleared as well, which is why the assert fails, it thinks the geom still belongs to some space. I'm not even sure the asserts are that useful but in this case they caught an error :P

Thank you!

David

Oleh Derevenko

unread,
Jul 28, 2020, 7:45:55 PM7/28/20
to ode-...@googlegroups.com

Thank you David, fixed it.

Please use the latest commits in “0.16.x” or “master”.

 

Oleh Derevenko

-- Skype with underscore
GPG Key Fingerprint: 2F56 32DC DCD9 B2BB 06E9 39E8 A37E 5E60 376E C691

 

From: ode-...@googlegroups.com <ode-...@googlegroups.com> On Behalf Of David Guillen Fandos
Sent: Tuesday, July 28, 2020 9:27 PM
To: ode-...@googlegroups.com
Subject: Re: Re: [ode-users] Bug in QuadTree space?

 

Hey there!

 

Ok so taking a look back in history, since I know my old code used to work well in an older version of ODE (back in 2012, version 0.11 or so IIRC).

openpgp-digital-signature.asc
Reply all
Reply to author
Forward
0 new messages