Merge pull request #3141 from ocadotechnology:recompile-release-gil
PiperOrigin-RevId: 883109831 Change-Id: I75c22ec071aae8f78b8354de40d8f58e8e952a50
This commit is contained in:
@@ -77,7 +77,18 @@ py::tuple RecompileSpec(raw::MjSpec* spec, const MjModelWrapper& old_m,
|
|||||||
raw::MjModel* m = static_cast<raw::MjModel*>(mju_malloc(sizeof(mjModel)));
|
raw::MjModel* m = static_cast<raw::MjModel*>(mju_malloc(sizeof(mjModel)));
|
||||||
m->buffer = nullptr;
|
m->buffer = nullptr;
|
||||||
raw::MjData* d = mj_copyData(nullptr, old_m.get(), old_d.get());
|
raw::MjData* d = mj_copyData(nullptr, old_m.get(), old_d.get());
|
||||||
if (mj_recompile(spec, nullptr, m, d)) {
|
|
||||||
|
bool compile_failed = false;
|
||||||
|
|
||||||
|
{
|
||||||
|
// Release GIL before calling mj_recompile which may spawn threads
|
||||||
|
py::gil_scoped_release no_gil;
|
||||||
|
if (mj_recompile(spec, nullptr, m, d)) {
|
||||||
|
compile_failed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compile_failed) {
|
||||||
throw py::value_error(mjs_getError(spec));
|
throw py::value_error(mjs_getError(spec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -400,7 +400,18 @@ py::tuple RecompileSpec(raw::MjSpec* spec, const MjModelWrapper& old_m,
|
|||||||
raw::MjModel* m = static_cast<raw::MjModel*>(mju_malloc(sizeof(mjModel)));
|
raw::MjModel* m = static_cast<raw::MjModel*>(mju_malloc(sizeof(mjModel)));
|
||||||
m->buffer = nullptr;
|
m->buffer = nullptr;
|
||||||
raw::MjData* d = mj_copyData(nullptr, old_m.get(), old_d.get());
|
raw::MjData* d = mj_copyData(nullptr, old_m.get(), old_d.get());
|
||||||
if (mj_recompile(spec, nullptr, m, d)) {
|
|
||||||
|
bool compile_failed = false;
|
||||||
|
|
||||||
|
{
|
||||||
|
// Release GIL before calling mj_recompile which may spawn threads
|
||||||
|
py::gil_scoped_release no_gil;
|
||||||
|
if (mj_recompile(spec, nullptr, m, d)) {
|
||||||
|
compile_failed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compile_failed) {
|
||||||
throw py::value_error(mjs_getError(spec));
|
throw py::value_error(mjs_getError(spec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user