Skip to content

Commit

Permalink
Fixed issue when yield returning same request
Browse files Browse the repository at this point in the history
The issue occurs because when you yield return the same request multiple times, the state machine advances but it will not wait until the code is completely executed.
  • Loading branch information
Metious committed Nov 14, 2023
1 parent f655a4d commit 5201093
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Nautilus/Assets/ModPrefabCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void EnterPrefabIntoCache(GameObject prefab)
if(!Entries.ContainsKey(prefabIdentifier.classId))
{
Entries.Add(prefabIdentifier.classId, prefab);
InternalLogger.Debug($"ModPrefabCache: adding prefab {prefab}");
InternalLogger.Debug($"ModPrefabCache: added prefab {prefab}");
}
else // this should never happen
{
Expand Down
13 changes: 9 additions & 4 deletions Nautilus/Assets/ModPrefabRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace Nautilus.Assets;

// request for getting ModPrefab asynchronously
internal class ModPrefabRequest: IPrefabRequest, IEnumerator
internal class ModPrefabRequest: IPrefabRequest
{
private readonly PrefabInfo prefabInfo;

private int state = 0;

private CoroutineTask<GameObject> task;

private TaskResult<GameObject> taskResult;

public ModPrefabRequest(PrefabInfo prefabInfo)
Expand Down Expand Up @@ -56,7 +56,12 @@ public bool TryGetPrefab(out GameObject result)
public bool MoveNext()
{
Init();
return state++ == 0;
if (task == null)
{
return false;
}

return !TryGetPrefab(out _);
}

public void Reset() {}
Expand Down

0 comments on commit 5201093

Please sign in to comment.