From 3e7575c4b2579d9d4aa08a40b64189fa8a7f0076 Mon Sep 17 00:00:00 2001 From: Mergul Date: Mon, 15 Jun 2020 17:21:29 +0200 Subject: [PATCH] Bug fixes -fix: UnittestRunner don't catch RangeError -fix: sometimes onUpdate was called with empty array of entities --- source/bubel/ecs/manager.d | 28 +++++++++++++++++++++++++--- tests/runner.d | 9 ++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/source/bubel/ecs/manager.d b/source/bubel/ecs/manager.d index 4c543ce..132ab62 100644 --- a/source/bubel/ecs/manager.d +++ b/source/bubel/ecs/manager.d @@ -1011,7 +1011,8 @@ export struct EntityManager if (entities_count > 0) { assert(entities_count <= block.entities_count - && offset <= block.entities_count); + && offset < block.entities_count); + assert(entities_count > offset); fillInputData(input_data, info, block, offset, entities_count, system); @@ -1489,21 +1490,27 @@ export struct EntityManager if (first_block is null || blocks_count == 0) continue; + //if this info will fill job if ((blocks_count - 1) * info.max_entities + entities_count + info.last_block.entities_count - first_elem >= entities_per_job) { int reamaining_entities = (entities_per_job - entities_count - ( first_block.entities_count - first_elem)); - if (reamaining_entities >= 0) + + //if first block don't fill job + if (reamaining_entities > 0) { + //take as many full blocks as possible int full_blocks_count = reamaining_entities / info.max_entities; EntitiesBlock* block = first_block; foreach (i; 0 .. full_blocks_count + 1) block = block.next_block; + //if full block + actual contained entities + remaining entities form first block > entities count per job if (full_blocks_count * info.max_entities + entities_count + ( first_block.entities_count - first_elem) >= entities_per_job) { + assert(entities_per_job == full_blocks_count * info.max_entities + entities_count + (first_block.entities_count - first_elem)); CallData data = CallData(caller.system_id, sys, info, sys.m_update_delegate, first_block, cast(ushort)(full_blocks_count + 1), @@ -1518,6 +1525,8 @@ export struct EntityManager entities_count += full_blocks_count * info.max_entities + ( first_block.entities_count - first_elem); // - first_elem; uint last_elem = entities_per_job - entities_count; // + first_elem - 1; + assert(last_elem > 0); + assert(last_elem <= block.entities_count); CallData data = CallData(caller.system_id, sys, info, sys.m_update_delegate, first_block, cast(ushort)(full_blocks_count + 2), @@ -1525,19 +1534,31 @@ export struct EntityManager tmp_datas.add(data); first_elem = last_elem; blocks_count -= full_blocks_count + 1; - assert(first_elem <= block.entities_count); first_block = block; + if(last_elem == block.entities_count) + { + assert(block.next_block == null); + first_block = null; + } } } else { uint last_elem = entities_per_job - entities_count; + assert(last_elem > 0); CallData data = CallData(caller.system_id, sys, info, sys.m_update_delegate, first_block, 1, cast(ushort) first_elem, cast(ushort)(first_elem + last_elem)); tmp_datas.add(data); first_elem += last_elem; assert(first_elem <= first_block.entities_count); + //if job takes every entity, take next block + if(first_elem == first_block.entities_count) + { + first_elem = 0; + first_block = first_block.next_block; + blocks_count--; + } } nextJob(); entities_count = 0; @@ -1545,6 +1566,7 @@ export struct EntityManager } else { + //take whole info blocks CallData data = CallData(caller.system_id, sys, info, sys.m_update_delegate, first_block, cast(ushort) blocks_count, cast(ushort) first_elem); tmp_datas.add(data); diff --git a/tests/runner.d b/tests/runner.d index 7e3dd07..83c2288 100644 --- a/tests/runner.d +++ b/tests/runner.d @@ -236,7 +236,7 @@ struct TestRunner(Args...) } else { - import core.exception : AssertError; + import core.exception : AssertError, RangeError; try { unittest_(); @@ -249,6 +249,13 @@ struct TestRunner(Args...) test.file_line = cast(int)error.line; test.msg = copyString(error.msg); } + catch(RangeError error) + { + test.passed = false; + test.file = copyString(error.file); + test.file_line = cast(int)error.line; + test.msg = copyString(error.msg); + } } if (test.passed)