Skip to content

Commit

Permalink
Fixed crash in Python API when using several cameras with different r…
Browse files Browse the repository at this point in the history
…esolutions (cyberbotics#5705)

* Fixed crash in Python API when using several cameras with different resolutions

* Update changelog-r2023.md
  • Loading branch information
omichel authored Jan 3, 2023
1 parent 6f5751c commit 4a25df9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/reference/changelog-r2023.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Released on ??
- Disable `Select..` button in SFString editor if the field has restricted values ([5663](https://github.com/cyberbotics/webots/pull/5663)).
- Improved plot representation in default robot window when a NaN value is received from a device ([#5680](https://github.com/cyberbotics/webots/pull/5680)).
- Bug Fixes
- Fixed crash in Python API when a robot controller was using several cameras with different resolutions ([#5705](https://github.com/cyberbotics/webots/pull/5705)).
- Fixed Python API `Supervisor.setSimulationMode` which was failing ([#5603](https://github.com/cyberbotics/webots/pull/5603)).
- Fixed Python API `Node.enableContactPointsTracking` which was failing ([#5633](https://github.com/cyberbotics/webots/pull/5633)).
- Fixed Python API field getters sometimes returning an invalid Field object ([#5633](https://github.com/cyberbotics/webots/pull/5633)).
Expand Down
6 changes: 2 additions & 4 deletions lib/controller/python/controller/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ def __init__(self, name: Union[str, int], sampling_period: int = None):
self._enable = wb.wb_camera_enable
self._get_sampling_period = wb.wb_camera_get_sampling_period
super().__init__(name, sampling_period)
width = self.width
height = self.height
wb.wb_camera_get_image.restype = ctypes.POINTER(ctypes.c_ubyte * (4 * width * height))
wb.wb_camera_recognition_get_segmentation_image.restype = ctypes.POINTER(ctypes.c_ubyte * (4 * width * height))

def getExposure(self) -> float:
return self.exposure
Expand Down Expand Up @@ -161,10 +157,12 @@ def setFov(self, f: float):

@property
def image(self) -> bytes:
wb.wb_camera_get_image.restype = ctypes.POINTER(ctypes.c_ubyte * (4 * self.width * self.height))
return bytes(wb.wb_camera_get_image(self._tag).contents)

@property
def segmentation_image(self) -> bytes:
wb.wb_camera_recognition_get_segmentation_image.restype = ctypes.POINTER(ctypes.c_ubyte * (4 * self.width * self.height))
return bytes(wb.wb_camera_recognition_get_segmentation_image(self._tag).contents)

@property
Expand Down

0 comments on commit 4a25df9

Please sign in to comment.