浏览代码

Don't crash the application when an event is sent to a removed association

Yentl Van Tendeloo 7 年之前
父节点
当前提交
940c656981
共有 1 个文件被更改,包括 11 次插入7 次删除
  1. 11 7
      src/python_sccd/python_sccd_runtime/statecharts_core.py

+ 11 - 7
src/python_sccd/python_sccd_runtime/statecharts_core.py

@@ -347,13 +347,17 @@ class ObjectManagerBase(object):
             for current in currents:
                 association = current["instance"].associations[name]
                 if (index >= 0 ):
-                    nexts.append({
-                        "instance": association.instances[index],
-                        "ref": current["instance"],
-                        "assoc_name": name,
-                        "assoc_index": index,
-                        "path": current["path"] + ("" if current["path"] == "" else "/") + name + "[" + str(index) + "]"
-                    })
+                    try:
+                        nexts.append({
+                            "instance": association.instances[index],
+                            "ref": current["instance"],
+                            "assoc_name": name,
+                            "assoc_index": index,
+                            "path": current["path"] + ("" if current["path"] == "" else "/") + name + "[" + str(index) + "]"
+                        })
+                    except KeyError:
+                        # Entry was removed, so ignore this request
+                        pass
                 elif (index == -1):
                     for i in association.instances:
                         nexts.append({