Skip to content

Commit bf59a7a

Browse files
committed
Bug fixes.
1 parent f7582ab commit bf59a7a

5 files changed

Lines changed: 49 additions & 14 deletions

File tree

Arch.LowLevel/Arch.LowLevel.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
<PackageId>Arch.LowLevel</PackageId>
1515
<Title>Arch.LowLevel</Title>
16-
<Version>1.1.3</Version>
16+
<Version>1.1.4</Version>
1717
<Authors>genaray</Authors>
1818
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1919
<Description>LowLevel tools for arch.</Description>
2020
<PackageReleaseNotes>Refactored JaggedArrays.
2121
Increased performance of JaggedArrays.
2222
Added Array, a new class that acts as a Wrapper around normal generic Arrays for unsafe operations.
23-
Added tests. </PackageReleaseNotes>
23+
Added tests.
24+
Bug fixes.</PackageReleaseNotes>
2425
<PackageTags>c#;.net;.net6;.net7;ecs;game;entity;gamedev; game-development; game-engine; entity-component-system; arch;</PackageTags>
2526

2627
<PackageProjectUrl>https://github.com/genaray/Arch.Extended</PackageProjectUrl>

Arch.LowLevel/Jagged/SparseJaggedArray.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,17 @@ public bool TryGetValue(int index, out T value)
259259
}
260260

261261
IndexToSlot(index, out var bucketIndex, out var itemIndex);
262-
ref var item = ref GetBucket(bucketIndex)[itemIndex];
263-
262+
263+
// Bucket empty? return false
264+
ref var bucket = ref GetBucket(bucketIndex);
265+
if (bucket.IsEmpty)
266+
{
267+
value = _filler;
268+
return false;
269+
}
270+
264271
// If the item is the default then the nobody set its value.
272+
ref var item = ref bucket[itemIndex];
265273
if (EqualityComparer<T>.Default.Equals(item, _filler))
266274
{
267275
value = _filler;
@@ -289,9 +297,17 @@ public ref T TryGetValue(int index, out bool @bool)
289297
}
290298

291299
IndexToSlot(index, out var bucketIndex, out var itemIndex);
292-
ref var item = ref GetBucket(bucketIndex)[itemIndex];
293-
300+
301+
// Bucket empty? return false
302+
ref var bucket = ref GetBucket(bucketIndex);
303+
if (bucket.IsEmpty)
304+
{
305+
@bool = false;
306+
return ref Unsafe.NullRef<T>();
307+
}
308+
294309
// If the item is the default then the nobody set its value.
310+
ref var item = ref bucket[itemIndex];
295311
if (EqualityComparer<T>.Default.Equals(item, _filler))
296312
{
297313
@bool = false;
@@ -316,8 +332,9 @@ public bool ContainsKey(int index)
316332
}
317333

318334
IndexToSlot(index, out var bucketIndex, out var itemIndex);
319-
ref var bucket = ref GetBucket(bucketIndex);
320335

336+
// If bucket empty return false
337+
ref var bucket = ref GetBucket(bucketIndex);
321338
if (bucket.IsEmpty)
322339
{
323340
return false;

Arch.LowLevel/Jagged/UnsafeSparseJaggedArray.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,17 @@ public bool TryGetValue(int index, out T value)
268268
}
269269

270270
IndexToSlot(index, out var bucketIndex, out var itemIndex);
271-
ref var item = ref GetBucket(bucketIndex)[itemIndex];
271+
272+
// Bucket empty? return false
273+
ref var bucket = ref GetBucket(bucketIndex);
274+
if (bucket.IsEmpty)
275+
{
276+
value = _filler;
277+
return false;
278+
}
272279

273280
// If the item is the default then the nobody set its value.
281+
ref var item = ref bucket[itemIndex];
274282
if (EqualityComparer<T>.Default.Equals(item, _filler))
275283
{
276284
value = _filler;
@@ -298,9 +306,17 @@ public ref T TryGetValue(int index, out bool @bool)
298306
}
299307

300308
IndexToSlot(index, out var bucketIndex, out var itemIndex);
301-
ref var item = ref GetBucket(bucketIndex)[itemIndex];
302-
309+
310+
// Bucket empty? return false
311+
ref var bucket = ref GetBucket(bucketIndex);
312+
if (bucket.IsEmpty)
313+
{
314+
@bool = false;
315+
return ref Unsafe.NullRef<T>();
316+
}
317+
303318
// If the item is the default then the nobody set its value.
319+
ref var item = ref bucket[itemIndex];
304320
if (EqualityComparer<T>.Default.Equals(item, _filler))
305321
{
306322
@bool = false;
@@ -325,8 +341,9 @@ public bool ContainsKey(int index)
325341
}
326342

327343
IndexToSlot(index, out var bucketIndex, out var itemIndex);
344+
345+
// If bucket empty return false
328346
ref var bucket = ref GetBucket(bucketIndex);
329-
330347
if (bucket.IsEmpty)
331348
{
332349
return false;

Arch.System.SourceGenerator/Query.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ partial class {{queryMethod.ClassName}}{
304304
);
305305
306306
private {{staticModifier}} World? _{{queryMethod.MethodName}}_Initialized;
307-
private {{staticModifier}} Query _{{queryMethod.MethodName}}_Query;
307+
private {{staticModifier}} Query? _{{queryMethod.MethodName}}_Query;
308308
309309
[MethodImpl(MethodImplOptions.AggressiveInlining)]
310310
public {{staticModifier}} void {{queryMethod.MethodName}}Query(World world {{data}}){
@@ -380,7 +380,7 @@ partial class {{queryMethod.ClassName}}{
380380
);
381381
382382
private {{staticModifier}} World? _{{queryMethod.MethodName}}_Initialized;
383-
private {{staticModifier}} Query _{{queryMethod.MethodName}}_Query;
383+
private {{staticModifier}} Query? _{{queryMethod.MethodName}}_Query;
384384
385385
private struct {{queryMethod.MethodName}}QueryJobChunk : IChunkJob
386386
{

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Download the packages and get started today!
1616
dotnet add package Arch.System --version 1.1.0
1717
dotnet add package Arch.System.SourceGenerator --version 2.0.0
1818
dotnet add package Arch.EventBus --version 1.0.2
19-
dotnet add package Arch.LowLevel --version 1.1.3
19+
dotnet add package Arch.LowLevel --version 1.1.4
2020
dotnet add package Arch.Relationships --version 1.0.0
2121
dotnet add package Arch.Persistence --version 2.0.0
2222
dotnet add package Arch.AOT.SourceGenerator --version 1.0.1

0 commit comments

Comments
 (0)