[ui] Check that viewpoints still exist before accessing their metadata

The metadata value of the viewpoint is meant to be a string, but if the
viewpoint attribute has already been removed and does not exist anymore,
then the metadata value becomes a PySide property.

When trying to access that property, an exception is raised. This commit
avoids raising exceptions in that case by checking that the viewpoint
attribute still exists (the metadata value is a string instance) before
accessing the metadata value.

This fixes the "Failed to parse Viewpoint metadata: 'the JSON object must
be str, bytes or bytearray, not Property'" warning raised by the exception
which occurred every single time there was a switch between cameraInit
groups that had been cleared.
This commit is contained in:
Candice Bentéjac 2023-02-15 18:01:40 +01:00
parent 7bdd7cf9d6
commit 1576bfd43d

View file

@ -213,7 +213,8 @@ class ViewpointWrapper(QObject):
else: else:
self._initialIntrinsics = self._reconstruction.getIntrinsic(self._viewpoint) self._initialIntrinsics = self._reconstruction.getIntrinsic(self._viewpoint)
try: try:
self._metadata = json.loads(self._viewpoint.metadata.value) if self._viewpoint.metadata.value else None # When the viewpoint attribute has already been deleted, metadata.value becomes a PySide property (whereas a string is expected)
self._metadata = json.loads(self._viewpoint.metadata.value) if isinstance(self._viewpoint.metadata.value, str) and self._viewpoint.metadata.value else None
except Exception as e: except Exception as e:
logging.warning("Failed to parse Viewpoint metadata: '{}', '{}'".format(str(e), str(self._viewpoint.metadata.value))) logging.warning("Failed to parse Viewpoint metadata: '{}', '{}'".format(str(e), str(self._viewpoint.metadata.value)))
self._metadata = {} self._metadata = {}