Skip to content

Commit

Permalink
Protecting property widget exception when a label returns an invalid …
Browse files Browse the repository at this point in the history
…data tuple for the current selected property label: Sentry reported this error: OPENSHOT-43. This also fixes a regression related to updating ObjectDetector and Tracker objects.
  • Loading branch information
jonoomph committed Apr 13, 2023
1 parent 8ff253e commit 788266e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
20 changes: 14 additions & 6 deletions src/windows/models/properties_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
property_type = property[1]["type"]
property_key = property[0]
object_id = property[1]["object_id"]
objects = {}
clip_id, item_type = item.data()

# Get value (if any)
Expand Down Expand Up @@ -478,12 +479,16 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
# Get effect object
c = Effect.get(id=clip_id)

if c:
if c and c.data:

# Create reference
clip_data = c.data
if object_id:
clip_data = c.data.get('objects').get(object_id)
objects = c.data.get('objects', {})
clip_data = objects.pop(object_id, {})
if not clip_data:
log.debug("No clip data found for this object id")
return

# Update clip attribute
if property_key in clip_data:
Expand Down Expand Up @@ -616,9 +621,12 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
has_waveform = True

# Reduce # of clip properties we are saving (performance boost)
clip_data = {property_key: clip_data.get(property_key)}
if object_id:
clip_data = {'objects': {object_id: clip_data}}
if not object_id:
clip_data = {property_key: clip_data.get(property_key)}
else:
# If objects dict detected - don't reduce the # of objects
objects[object_id] = clip_data
clip_data = {'objects': objects}

# Save changes
if clip_updated:
Expand Down Expand Up @@ -766,7 +774,7 @@ def set_property(self, property, filter, c, item_type, object_id=None):
# Append ROW to MODEL (if does not already exist in model)
self.model.appendRow(row)

else:
elif name in self.items and self.items[name]["row"]:
# Update the value of the existing model
# Get 1st Column
col = self.items[name]["row"][0]
Expand Down
47 changes: 26 additions & 21 deletions src/windows/video_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,25 +475,26 @@ def paintEvent(self, event, *args):
raw_properties_effect = json.loads(self.transforming_effect_object.PropertiesJSON(clip_frame_number))
# Get properties for the first object in dict. PropertiesJSON should return one object at the time
tmp = raw_properties_effect.get('objects')
obj_id = list(tmp.keys())[0]
raw_properties_effect = raw_properties_effect.get('objects').get(obj_id)

# Check if the tracked object is visible in this frame
if raw_properties_effect.get('visible'):
if raw_properties_effect.get('visible').get('value') == 1:
# Get the selected bounding box values
rotation = raw_properties_effect['rotation']['value']
x1 = raw_properties_effect['x1']['value']
y1 = raw_properties_effect['y1']['value']
x2 = raw_properties_effect['x2']['value']
y2 = raw_properties_effect['y2']['value']
self.drawTransformHandler(
painter,
sx, sy,
source_width, source_height,
origin_x, origin_y,
x1, y1, x2, y2,
rotation)
if tmp:
obj_id = list(tmp.keys())[0]
raw_properties_effect = raw_properties_effect.get('objects').get(obj_id)

# Check if the tracked object is visible in this frame
if raw_properties_effect.get('visible'):
if raw_properties_effect.get('visible').get('value') == 1:
# Get the selected bounding box values
rotation = raw_properties_effect['rotation']['value']
x1 = raw_properties_effect['x1']['value']
y1 = raw_properties_effect['y1']['value']
x2 = raw_properties_effect['x2']['value']
y2 = raw_properties_effect['y2']['value']
self.drawTransformHandler(
painter,
sx, sy,
source_width, source_height,
origin_x, origin_y,
x1, y1, x2, y2,
rotation)
else:
self.drawTransformHandler(
painter,
Expand Down Expand Up @@ -1055,10 +1056,14 @@ def mouseMoveEvent(self, event):
if self.transforming_effect_object.info.has_tracked_object:
# Get properties of effect at current frame
raw_properties = json.loads(self.transforming_effect_object.PropertiesJSON(clip_frame_number))
objects = raw_properties.get('objects', {})
if not objects:
return

# Get properties for the first object in dict.
# PropertiesJSON should return one object at the time
obj_id = list(raw_properties.get('objects').keys())[0]
raw_properties = raw_properties.get('objects').get(obj_id)
obj_id = list(objects.keys())[0]
raw_properties = objects.get(obj_id)

if not raw_properties.get('visible'):
self.mouse_position = event.pos()
Expand Down
20 changes: 6 additions & 14 deletions src/windows/views/properties_tableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def mouseMoveEvent(self, event):
self.selected_item = model.item(row, 1)

# Is the user dragging on the value column
if self.selected_label and self.selected_item:
if self.selected_label and self.selected_item and \
self.selected_label.data() and type(self.selected_label.data()) == tuple:
# Ignore undo/redo history temporarily (to avoid a huge pile of undo/redo history)
get_app().updates.ignore_history = True

Expand Down Expand Up @@ -344,7 +345,7 @@ def doubleClickedCB(self, model_index):
selected_label = model.item(row, 0)
self.selected_item = model.item(row, 1)

if selected_label:
if selected_label and selected_label.data() and type(selected_label.data()) == tuple:
cur_property = selected_label.data()
property_type = cur_property[1]["type"]

Expand Down Expand Up @@ -436,23 +437,14 @@ def contextMenuEvent(self, event):
_ = get_app()._tr

# If item selected
if selected_label:
if selected_label and selected_label.data() and type(selected_label.data()) == tuple:
cur_property = selected_label.data()

# Clear menu if models updated
if self.menu_reset:
self.choices = []
self.menu_reset = False

# Get data from selected item
try:
cur_property = self.selected_label.data()
except Exception:
log.debug('Failed to access data on selected label widget')
return

if type(cur_property) != tuple:
log.debug('Failed to access valid data on current selected label widget')
return

property_name = cur_property[1]["name"]
self.property_type = cur_property[1]["type"]
points = cur_property[1]["points"]
Expand Down

0 comments on commit 788266e

Please sign in to comment.