talmolab / sleap

A deep learning framework for multi-animal pose tracking.
https://sleap.ai
Other
435 stars 97 forks source link

Do not try to remove item if already deleted #1498

Closed roomrys closed 1 year ago

roomrys commented 1 year ago

Description

In making some changes to the removal of overlays in #1421 (sub-PR: #1435), we reintroduced an error:

Traceback (most recent call last):
  File "C:\Users\lblab\.conda\envs\sleap\lib\site-packages\sleap\gui\app.py", line 1235, in _after_plot_change
    overlay.redraw(self.state["video"], frame_idx)
  File "C:\Users\lblab\.conda\envs\sleap\lib\site-packages\sleap\gui\overlays\base.py", line 74, in redraw
    self.remove_from_scene(*args, **kwargs)
  File "C:\Users\lblab\.conda\envs\sleap\lib\site-packages\sleap\gui\overlays\base.py", line 67, in remove_from_scene
    self.player.scene.removeItem(item)
RuntimeError: Internal C++ object (PySide2.QtWidgets.QGraphicsPathItem) already deleted.
Traceback (most recent call last):
  File "C:\Users\lblab\.conda\envs\sleap\lib\site-packages\sleap\gui\app.py", line 1235, in _after_plot_change
    overlay.redraw(self.state["video"], frame_idx)
  File "C:\Users\lblab\.conda\envs\sleap\lib\site-packages\sleap\gui\overlays\base.py", line 74, in redraw
    self.remove_from_scene(*args, **kwargs)
  File "C:\Users\lblab\.conda\envs\sleap\lib\site-packages\sleap\gui\overlays\base.py", line 67, in remove_from_scene
    self.player.scene.removeItem(item)
RuntimeError: Internal C++ object (PySide2.QtWidgets.QGraphicsPathItem) already deleted.

This is likely due to already removing the items in the overlay, but still keeping track of these items and then trying to remove them again. Even with this PR, if we enable DEBUG logging, then we will see that there are already deleted items trying to be removed.

This PR adds a try except around the item removal and removals all items from the tracked list of items after deleting them from the scene.

Types of changes

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

Thank you for contributing to SLEAP!

:heart:

Summary by CodeRabbit


coderabbitai[bot] commented 1 year ago

Walkthrough

This update enhances the robustness of the SLEAP GUI overlay system. It introduces better error handling when removing items from the scene, and improves tracking logic to ensure items are untracked post-removal.

Changes

File Summary
.../sleap/gui/overlays/base.py Introduced a logger for improved debugging. Added exception handling to manage potential RuntimeError during item removal from the scene. Updated remove_from_scene method to cease tracking of items once removed.

🐇💻

In the land of code where the shadows lie, A rabbit hopped in, with a twinkle in its eye. With a tap and a click, and a debug log, He fixed the errors hidden in the fog. Now the items vanish without a trace, In the GUI's gentle embrace. 🎉

Tips ### Chat with CodeRabbit Bot (`@coderabbitai`) - Mention `@coderabbitai` in any *review comment* for bot assistance. - Note: Review comments are made on code diffs or files, not on the PR overview. ### Pause Incremental Reviews - Insert `@coderabbitai: ignore` in the PR description to halt the bot's ongoing reviews. Remove the line to resume.