Assertion failure when removing a component while an entity is being destroyed
まだ誰も着手していません。
評価
調査の方向性
EntityManager::destroy(Entity::Id entity) から始め、削除ループ中にコンポーネントのデストラクタから Entity::remove() がどのように呼び出されるかを調べます。あるコンポーネントが別のコンポーネントを削除する破棄を再現し、その後 assertion が発生しなくなり、すべてのコンポーネントが一度だけ削除されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Hi,
I noticed that when you are destroying an entity, if you attempt to remove another component from that entity at the same time (e.g: from a component's destructor), you will get an assertion failure in Entity::remove()
As far as I could investigate, the issue is located in EntityManager::destroy(Entity::Id entity).
Old code:
void destroy(Entity::Id entity) {
assert_valid(entity);
uint32_t index = entity.index();
auto mask = entity_component_mask_[index];
for (size_t i = 0; i < component_helpers_.size(); i++) {
BaseComponentHelper *helper = component_helpers_[i];
if (helper && mask.test(i))
helper->remove_component(Entity(this, entity));
}
event_manager_.emit<EntityDestroyedEvent>(Entity(this, entity));
entity_component_mask_[index].reset();
entity_version_[index]++;
free_list_.push_back(index);
}
New code that fixes the issue:
void destroy(Entity::Id entity) {
assert_valid(entity);
uint32_t index = entity.index();
for (size_t i = 0; i < component_helpers_.size(); i++) {
BaseComponentHelper *helper = component_helpers_[i];
if (helper && entity_component_mask_[index].test(i))
helper->remove_component(Entity(this, entity));
}
event_manager_.emit<EntityDestroyedEvent>(Entity(this, entity));
entity_component_mask_[index].reset();
entity_version_[index]++;
free_list_.push_back(index);
}
The issue is caused by the fact mask is being cached before the for loop. As a result, if there is any attempt to remove a component in an other component's destructor, the so called component will be removed twice, hence causing the assertion failure.
Since I'm not in a situation where I can commit anything and/or submit a PR for a few days, I just wanted to let you know about the issue and the fix ;)
Best regards.
- 主要言語
- C++
- スター
- 2.3k
- フォーク
- 300
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
alecthomas/entityx のほかの issue
-
Test Failsオープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
alecthomas/entityx#256 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 32/100
alecthomas/entityx#246 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
alecthomas/entityx#238 · コメント 11 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
alecthomas/entityx#237 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
alecthomas/entityx#227 · コメント 2 件 ·
alecthomas/entityx の issue をすべて見る
似ている issue
-
agent:Windows bug parity performance pri:medium sev:low tooling windows
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
ai_p2
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
ClickHouse/ClickHouse#132519 ·
メンテナーはふだん 1 日以内に返信
-
patch_advisor_json_integration fails when the build tree is reached through a symbolic link対応中かも @DerKarussellbremser が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
boykopovar/AnyPS5#22581 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
BlueQuartzSoftware/simplnx#1987 ·
メンテナーはふだん 6 日以内に返信