CVHub520 / X-AnyLabeling

Effortless data labeling with AI support from Segment Anything and other awesome models.
GNU General Public License v3.0
3.04k stars 345 forks source link

修复了在调整OBB框体时程序会崩溃的问题 #388

Closed AreChen closed 1 month ago

AreChen commented 2 months ago

在调整OBB框体时,有时候会触发以下报错,导致程序崩溃

Traceback (most recent call last):
  File "I:\git\X-AnyLabeling\.\anylabeling\views\labeling\widgets\canvas.py", line 1505, in keyReleaseEvent
    index = self.shapes.index(self.selected_shapes[0])
ValueError: <anylabeling.views.labeling.shape.Shape object at 0x000001FAE270B4C0> is not in list

从 self.shapes 列表中找到 self.selected_shapes[0] 的索引,但是 self.selected_shapes[0] 并不存在于 self.shapes 列表中。这种情况通常发生在以下几种情况:

对象不匹配:self.selected_shapes[0] 可能已经从 self.shapes 中被移除,或者被修改过,导致无法通过 index() 方法找到相同的对象。

逻辑错误:在某些操作中可能意外地修改了 self.shapes 或 self.selected_shapes,导致两者不同步。

为了解决这个问题,采取了以下步骤:

  1. 检查和修正对象的管理 确保在任何操作中,self.shapes 和 self.selected_shapes 都正确地被更新和维护。例如,在删除或添加形状时,确保这两个列表都得到相应的更新。

  2. 增加异常处理 在尝试获取索引之前,首先检查对象是否存在于列表中。

CVHub520 commented 2 months ago

Hi, thank you for bringing this issue to our attention.

For further details or assistance with this matter, please try the following:

try:
    xxx
except ValueError:
    # Handle the potential error appropriately
    print("Selected shape not found in the list of shapes.")

You can resubmit according to the requirements. If there are no issues, I will merge this PR after the next modification. Thank you again for your support of X-AnyLabeling.