Bug fixes
-fix: UnittestRunner don't catch RangeError -fix: sometimes onUpdate was called with empty array of entities
This commit is contained in:
parent
d733bb514c
commit
3e7575c4b2
2 changed files with 33 additions and 4 deletions
|
|
@ -1011,7 +1011,8 @@ export struct EntityManager
|
||||||
if (entities_count > 0)
|
if (entities_count > 0)
|
||||||
{
|
{
|
||||||
assert(entities_count <= block.entities_count
|
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);
|
fillInputData(input_data, info, block, offset, entities_count, system);
|
||||||
|
|
||||||
|
|
@ -1489,21 +1490,27 @@ export struct EntityManager
|
||||||
if (first_block is null || blocks_count == 0)
|
if (first_block is null || blocks_count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
//if this info will fill job
|
||||||
if ((blocks_count - 1) * info.max_entities + entities_count
|
if ((blocks_count - 1) * info.max_entities + entities_count
|
||||||
+ info.last_block.entities_count - first_elem >= entities_per_job)
|
+ info.last_block.entities_count - first_elem >= entities_per_job)
|
||||||
{
|
{
|
||||||
int reamaining_entities = (entities_per_job - entities_count - (
|
int reamaining_entities = (entities_per_job - entities_count - (
|
||||||
first_block.entities_count - first_elem));
|
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;
|
int full_blocks_count = reamaining_entities / info.max_entities;
|
||||||
EntitiesBlock* block = first_block;
|
EntitiesBlock* block = first_block;
|
||||||
foreach (i; 0 .. full_blocks_count + 1)
|
foreach (i; 0 .. full_blocks_count + 1)
|
||||||
block = block.next_block;
|
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 + (
|
if (full_blocks_count * info.max_entities + entities_count + (
|
||||||
first_block.entities_count - first_elem) >= entities_per_job)
|
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,
|
CallData data = CallData(caller.system_id, sys,
|
||||||
info, sys.m_update_delegate, first_block,
|
info, sys.m_update_delegate, first_block,
|
||||||
cast(ushort)(full_blocks_count + 1),
|
cast(ushort)(full_blocks_count + 1),
|
||||||
|
|
@ -1518,6 +1525,8 @@ export struct EntityManager
|
||||||
entities_count += full_blocks_count * info.max_entities + (
|
entities_count += full_blocks_count * info.max_entities + (
|
||||||
first_block.entities_count - first_elem); // - first_elem;
|
first_block.entities_count - first_elem); // - first_elem;
|
||||||
uint last_elem = entities_per_job - entities_count; // + first_elem - 1;
|
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,
|
CallData data = CallData(caller.system_id, sys,
|
||||||
info, sys.m_update_delegate, first_block,
|
info, sys.m_update_delegate, first_block,
|
||||||
cast(ushort)(full_blocks_count + 2),
|
cast(ushort)(full_blocks_count + 2),
|
||||||
|
|
@ -1525,19 +1534,31 @@ export struct EntityManager
|
||||||
tmp_datas.add(data);
|
tmp_datas.add(data);
|
||||||
first_elem = last_elem;
|
first_elem = last_elem;
|
||||||
blocks_count -= full_blocks_count + 1;
|
blocks_count -= full_blocks_count + 1;
|
||||||
assert(first_elem <= block.entities_count);
|
|
||||||
first_block = block;
|
first_block = block;
|
||||||
|
if(last_elem == block.entities_count)
|
||||||
|
{
|
||||||
|
assert(block.next_block == null);
|
||||||
|
first_block = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint last_elem = entities_per_job - entities_count;
|
uint last_elem = entities_per_job - entities_count;
|
||||||
|
assert(last_elem > 0);
|
||||||
CallData data = CallData(caller.system_id, sys,
|
CallData data = CallData(caller.system_id, sys,
|
||||||
info, sys.m_update_delegate, first_block, 1,
|
info, sys.m_update_delegate, first_block, 1,
|
||||||
cast(ushort) first_elem, cast(ushort)(first_elem + last_elem));
|
cast(ushort) first_elem, cast(ushort)(first_elem + last_elem));
|
||||||
tmp_datas.add(data);
|
tmp_datas.add(data);
|
||||||
first_elem += last_elem;
|
first_elem += last_elem;
|
||||||
assert(first_elem <= first_block.entities_count);
|
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();
|
nextJob();
|
||||||
entities_count = 0;
|
entities_count = 0;
|
||||||
|
|
@ -1545,6 +1566,7 @@ export struct EntityManager
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//take whole info blocks
|
||||||
CallData data = CallData(caller.system_id, sys, info, sys.m_update_delegate,
|
CallData data = CallData(caller.system_id, sys, info, sys.m_update_delegate,
|
||||||
first_block, cast(ushort) blocks_count, cast(ushort) first_elem);
|
first_block, cast(ushort) blocks_count, cast(ushort) first_elem);
|
||||||
tmp_datas.add(data);
|
tmp_datas.add(data);
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ struct TestRunner(Args...)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
import core.exception : AssertError;
|
import core.exception : AssertError, RangeError;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
unittest_();
|
unittest_();
|
||||||
|
|
@ -249,6 +249,13 @@ struct TestRunner(Args...)
|
||||||
test.file_line = cast(int)error.line;
|
test.file_line = cast(int)error.line;
|
||||||
test.msg = copyString(error.msg);
|
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)
|
if (test.passed)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue