Skip to content

Commit ca5b4e7

Browse files
committed
ode: fix OdeJoint.attach with None parameters
Fixes panda3d#633
1 parent 186d8fe commit ca5b4e7

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

panda/src/ode/odeJoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class EXPCL_PANDAODE OdeJoint : public TypedObject {
8383
INLINE void set_feedback(bool flag = true);
8484
INLINE OdeJointFeedback *get_feedback();
8585

86-
EXTENSION(void attach(const OdeBody *body1, const OdeBody *body2));
86+
EXTENSION(void attach(PyObject *body1, PyObject *body2));
8787
void attach_bodies(const OdeBody &body1, const OdeBody &body2);
8888
void attach_body(const OdeBody &body, int index);
8989
void detach();

panda/src/ode/odeJoint_ext.cxx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "odePlane2dJoint.h"
3030

3131
#ifndef CPPPARSER
32+
extern Dtool_PyTypedObject Dtool_OdeBody;
3233
extern Dtool_PyTypedObject Dtool_OdeJoint;
3334
extern Dtool_PyTypedObject Dtool_OdeBallJoint;
3435
extern Dtool_PyTypedObject Dtool_OdeHingeJoint;
@@ -48,7 +49,23 @@ extern Dtool_PyTypedObject Dtool_OdePlane2dJoint;
4849
* attached to the environment.
4950
*/
5051
void Extension<OdeJoint>::
51-
attach(const OdeBody *body1, const OdeBody *body2) {
52+
attach(PyObject *param1, PyObject *param2) {
53+
const OdeBody *body1 = nullptr;
54+
if (param1 != Py_None) {
55+
body1 = (const OdeBody *)DTOOL_Call_GetPointerThisClass(param1, &Dtool_OdeBody, 1, "OdeJoint.attach", true, true);
56+
if (body1 == nullptr) {
57+
return;
58+
}
59+
}
60+
61+
const OdeBody *body2 = nullptr;
62+
if (param2 != Py_None) {
63+
body2 = (const OdeBody *)DTOOL_Call_GetPointerThisClass(param2, &Dtool_OdeBody, 2, "OdeJoint.attach", true, true);
64+
if (body2 == nullptr) {
65+
return;
66+
}
67+
}
68+
5269
if (body1 && body2) {
5370
_this->attach_bodies(*body1, *body2);
5471

panda/src/ode/odeJoint_ext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
template<>
3131
class Extension<OdeJoint> : public ExtensionBase<OdeJoint> {
3232
public:
33-
void attach(const OdeBody *body1, const OdeBody *body2);
33+
void attach(PyObject *body1, PyObject *body2);
3434

3535
PyObject *convert() const;
3636
};

tests/ode/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def world():
6+
ode = pytest.importorskip("panda3d.ode")
7+
return ode.OdeWorld()

tests/ode/test_ode_joints.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import pytest
2+
3+
4+
def test_odejoint_attach_both(world):
5+
from panda3d import ode
6+
7+
body1 = ode.OdeBody(world)
8+
body2 = ode.OdeBody(world)
9+
10+
assert len(body1.joints) == 0
11+
assert len(body2.joints) == 0
12+
13+
joint = ode.OdeBallJoint(world)
14+
joint.attach(body1, body2)
15+
16+
assert tuple(body1.joints) == (joint,)
17+
assert tuple(body2.joints) == (joint,)
18+
19+
20+
def test_odejoint_attach_0(world):
21+
from panda3d import ode
22+
23+
body = ode.OdeBody(world)
24+
25+
assert len(body.joints) == 0
26+
27+
joint = ode.OdeBallJoint(world)
28+
joint.attach(body, None)
29+
30+
assert tuple(body.joints) == (joint,)
31+
32+
33+
def test_odejoint_attach_1(world):
34+
from panda3d import ode
35+
36+
body = ode.OdeBody(world)
37+
38+
assert len(body.joints) == 0
39+
40+
joint = ode.OdeBallJoint(world)
41+
joint.attach(None, body)
42+
43+
assert tuple(body.joints) == (joint,)

0 commit comments

Comments
 (0)