Skip to content

Commit

Permalink
Do not try to remove item if already deleted (#1498)
Browse files Browse the repository at this point in the history
* Do not try to remove item if already deleted

* Lint
  • Loading branch information
roomrys authored Sep 12, 2023
1 parent e4fca4f commit b8a37c4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions sleap/gui/overlays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
so that current frame must be redrawn).
"""

from qtpy import QtWidgets

import attr
import abc
import numpy as np
import logging
from typing import Sequence, Union, Optional, List

import attr
import numpy as np
from qtpy import QtWidgets
from qtpy.QtWidgets import QGraphicsItem

from sleap import Labels, Video
from sleap.gui.widgets.video import QtVideoPlayer
from sleap.nn.data.providers import VideoReader
from sleap.nn.inference import VisualPredictor

logger = logging.getLogger(__name__)


@attr.s(auto_attribs=True)
class BaseOverlay(abc.ABC):
Expand Down Expand Up @@ -64,7 +66,15 @@ def remove_from_scene(self):
if self.items is None:
return
for item in self.items:
self.player.scene.removeItem(item)
try:
self.player.scene.removeItem(item)

except RuntimeError as e: # Internal C++ object (PySide2.QtWidgets.QGraphicsPathItem) already deleted.
logger.debug(e)
pass

# Stop tracking the items after they been removed from the scene
self.items = []

def redraw(self, video, frame_idx, *args, **kwargs):
"""Remove all items from the scene before adding new items to the scene.
Expand Down

0 comments on commit b8a37c4

Please sign in to comment.