Skip to content

Commit ecff24c

Browse files
committed
**Fixed**:
- The endless loop when calling *RngService.Range()* - The endless loop *GameObjectPool* when spawning new entities
1 parent 64aec99 commit ecff24c

4 files changed

Lines changed: 24 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.12.1] - 2024-10-25
8+
9+
**Fixed**:
10+
- The endless loop when calling *RngService.Range()*
11+
- The endless loop *GameObjectPool* when spawning new entities
12+
713
## [0.12.0] - 2024-10-22
814

915
- Added IRngData to PoolService to suppprt read only data structure and allow abtract injection of data into other objects
@@ -51,13 +57,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5157

5258
## [0.7.1] - 2023-07-28
5359

54-
**Fixed**:
55-
- Compilation errors in various test files and the PoolService class have been fixed.
56-
5760
**Changed**:
5861
- Tests have been moved to proper folders, and the package number has been updated.
5962
- An unused namespace import has been removed from the InstallerTest class.
6063

64+
**Fixed**:
65+
- Compilation errors in various test files and the PoolService class have been fixed.
66+
6167
## [0.7.0] - 2023-07-28
6268

6369
- Introduced a code review process using GitHub Actions workflow.

Runtime/ObjectPool.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public class GameObjectPool : ObjectPoolBase<GameObject>
344344
/// If true then when the object is despawned back to the pool will be parented to the same as the sample entity
345345
/// parent transform
346346
/// </summary>
347-
public bool DespawnToSampleParent { get; set; }
347+
public bool DespawnToSampleParent { get; set; } = true;
348348

349349
public GameObjectPool(uint initSize, GameObject sampleEntity) : base(initSize, sampleEntity, Instantiator)
350350
{
@@ -375,7 +375,7 @@ public static GameObject Instantiator(GameObject entityRef)
375375

376376
protected override GameObject SpawnEntity()
377377
{
378-
var entity = SpawnEntity();
378+
var entity = base.SpawnEntity();
379379

380380
entity.SetActive(true);
381381

@@ -403,7 +403,7 @@ public class GameObjectPool<T> : ObjectPoolBase<T> where T : Behaviour
403403
/// If true then when the object is despawned back to the pool will be parented to the same as the sample entity
404404
/// parent transform
405405
/// </summary>
406-
public bool DespawnToSampleParent { get; set; }
406+
public bool DespawnToSampleParent { get; set; } = true;
407407

408408
public GameObjectPool(uint initSize, T sampleEntity) : base(initSize, sampleEntity, Instantiator)
409409
{
@@ -442,14 +442,17 @@ protected override T SpawnEntity()
442442
{
443443
T entity = null;
444444

445-
do
445+
while(entity == null)
446446
{
447-
entity = SpawnEntity();
447+
entity = base.SpawnEntity();
448+
449+
if(entity.gameObject == null)
450+
{
451+
SpawnedEntities.Remove(entity);
452+
453+
entity = null;
454+
}
448455
}
449-
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
450-
// Need to do while loop and check as parent objects could have destroyed the entity/gameobject before it could
451-
// be properly disposed by pool service
452-
while (entity == null || entity.gameObject == null);
453456

454457
entity.gameObject.SetActive(true);
455458

Runtime/RngService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public static int[] Restore(int count, int seed)
205205
/// </summary>
206206
public static int Range(int min, int max, int[] rndState, bool maxInclusive)
207207
{
208-
var floatMin = min;
209-
var floatMax = max;
208+
floatP floatMin = min;
209+
floatP floatMax = max;
210210

211211
return Range(floatMin, floatMax, rndState, maxInclusive);
212212
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.gamelovers.services",
33
"displayName": "Services",
44
"author": "Miguel Tomas",
5-
"version": "0.12.0",
5+
"version": "0.12.1",
66
"unity": "2022.4",
77
"license": "MIT",
88
"description": "The purpose of this package is to provide a set of services to ease the development of a basic game architecture",

0 commit comments

Comments
 (0)