Add a free() method to mujoco.MjrContext.
Up the mujoco bindings version to 2.1.2.post2. Keep the capsule deconstructor which calls mj_freeContext, because mjr_freeContext is idempotent. PiperOrigin-RevId: 435714183 Change-Id: I9f8615f85f2b3e383f447f6684e61200039d57d4
This commit is contained in:
committed by
Saran Tunyasuvunakool
parent
df202d23b1
commit
c6984b42af
@@ -37,6 +37,8 @@ class MjWrapper<raw::MjrContext> : public WrapperBase<raw::MjrContext> {
|
||||
MjWrapper(MjWrapper&&) = default;
|
||||
~MjWrapper() = default;
|
||||
|
||||
void Free();
|
||||
|
||||
#define X(var) py_array_or_tuple_t<mjtNum> var
|
||||
X(fogRGBA);
|
||||
X(auxWidth);
|
||||
@@ -121,6 +123,12 @@ MjrContextWrapper::MjWrapper(const MjModelWrapper& model, int fontscale)
|
||||
X(charWidthBig) {}
|
||||
#undef X_SKIN
|
||||
#undef X
|
||||
|
||||
void MjrContextWrapper::Free() {
|
||||
// mjr_freeContext is safe to call multiple times.
|
||||
InterceptMjErrors(mjr_freeContext)(ptr_);
|
||||
}
|
||||
|
||||
} // namespace _impl
|
||||
|
||||
namespace {
|
||||
@@ -156,6 +164,10 @@ PYBIND11_MODULE(_render, pymodule) {
|
||||
py::class_<MjrContextWrapper> mjrContext(pymodule, "MjrContext");
|
||||
mjrContext.def(py::init<>());
|
||||
mjrContext.def(py::init<const MjModelWrapper&, int>());
|
||||
mjrContext.def(
|
||||
"free", [](MjrContextWrapper& self) { self.Free(); },
|
||||
py::doc("Frees resources in current active OpenGL context, sets struct "
|
||||
"to default."));
|
||||
#define X(var) \
|
||||
mjrContext.def_property( \
|
||||
#var, [](const MjrContextWrapper& c) { return c.get()->var; }, \
|
||||
|
||||
Reference in New Issue
Block a user