Fix GIL-not-held bug in mjr_readPixels.
PiperOrigin-RevId: 441813459 Change-Id: I2f15cb77ca243b890fd0825ebbc9b910d3ece56f
This commit is contained in:
committed by
Copybara-Service
parent
87539dbd24
commit
0e5d062302
@@ -192,6 +192,14 @@ static constexpr void Def(
|
||||
::pybind11::call_guard<::pybind11::gil_scoped_release>());
|
||||
}
|
||||
|
||||
template <typename MjTraits, typename Func>
|
||||
MUJOCO_ALWAYS_INLINE
|
||||
static constexpr void DefWithGil(::pybind11::module_& m, Func&& func) {
|
||||
WithNamedArgs(MjTraits::param_names).def(
|
||||
m, MjTraits::name, util::UnwrapArgs(std::forward<Func>(func)),
|
||||
::pybind11::doc(MjTraits::doc));
|
||||
}
|
||||
|
||||
// Should only be invoked via the DEF_WITH_OMITTED_PY_ARGS macro.
|
||||
template <typename MjTraits, typename OmittedArgsTuple>
|
||||
struct DefWithOmittedPyArgsImpl {
|
||||
|
||||
+12
-6
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <mjrender.h>
|
||||
@@ -252,14 +253,19 @@ PYBIND11_MODULE(_render, pymodule) {
|
||||
Def<traits::mjr_uploadHField>(pymodule);
|
||||
Def<traits::mjr_restoreBuffer>(pymodule);
|
||||
Def<traits::mjr_setBuffer>(pymodule);
|
||||
Def<traits::mjr_readPixels>(
|
||||
pymodule, [](std::optional<py::array_t<uint8_t>> rgb,
|
||||
DefWithGil<traits::mjr_readPixels>(
|
||||
pymodule, [](std::optional<py::array_t<std::uint8_t>> rgb,
|
||||
std::optional<py::array_t<float>> depth,
|
||||
const raw::MjrRect* viewport, const raw::MjrContext* con) {
|
||||
return InterceptMjErrors(::mjr_readPixels)(
|
||||
rgb.has_value() ? rgb->mutable_data() : nullptr,
|
||||
depth.has_value() ? depth->mutable_data() : nullptr, *viewport,
|
||||
con);
|
||||
std::uint8_t* const rgb_data =
|
||||
rgb.has_value() ? rgb->mutable_data() : nullptr;
|
||||
float* const depth_data =
|
||||
depth.has_value() ? depth->mutable_data() : nullptr;
|
||||
{
|
||||
py::gil_scoped_release no_gil;
|
||||
return InterceptMjErrors(::mjr_readPixels)(rgb_data, depth_data,
|
||||
*viewport, con);
|
||||
}
|
||||
});
|
||||
Def<traits::mjr_drawPixels>(
|
||||
pymodule,
|
||||
|
||||
Reference in New Issue
Block a user