diff --git a/CHANGELOG.md b/CHANGELOG.md index 76037cde4..6f45b4b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ * Add keyword arguments for `carla.TrafficManager` Python API functions * Fixed bug causing the `FPixelReader::SavePixelsToDisk(PixelData, FilePath)` function to crash due to pixel array not set correctly. * Collisions detected by the CollisionSensor no longer generate more than one event per frame. + * Fixed segfaults in Python API due to incorrect GIL locking under Python 3.10. * Added API function to load a map only if it is different from the current one. ## CARLA 0.9.14 diff --git a/PythonAPI/carla/source/libcarla/Client.cpp b/PythonAPI/carla/source/libcarla/Client.cpp index f773b8a5f..34af2106a 100644 --- a/PythonAPI/carla/source/libcarla/Client.cpp +++ b/PythonAPI/carla/source/libcarla/Client.cpp @@ -22,9 +22,13 @@ static void SetTimeout(carla::client::Client &client, double seconds) { } static auto GetAvailableMaps(const carla::client::Client &self) { - carla::PythonUtil::ReleaseGIL unlock; boost::python::list result; - for (const auto &str : self.GetAvailableMaps()) { + std::vector maps; + { + carla::PythonUtil::ReleaseGIL unlock; + maps = self.GetAvailableMaps(); + } + for (const auto &str : maps) { result.append(str); } return result; diff --git a/PythonAPI/carla/source/libcarla/libcarla.cpp b/PythonAPI/carla/source/libcarla/libcarla.cpp index f56ea5c99..73998c2eb 100644 --- a/PythonAPI/carla/source/libcarla/libcarla.cpp +++ b/PythonAPI/carla/source/libcarla/libcarla.cpp @@ -139,8 +139,8 @@ std::vector PythonLitstToVector(boost::python::list &input) { } #define CALL_RETURNING_OPTIONAL_WITHOUT_GIL(cls, fn) +[](const cls &self) { \ - carla::PythonUtil::ReleaseGIL unlock; \ - auto optional = self.fn(); \ + auto call = CONST_CALL_WITHOUT_GIL(cls, fn); \ + auto optional = call(self); \ return optional.has_value() ? boost::python::object(*optional) : boost::python::object(); \ }