Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue when yield returning same request #498

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed issue when yield returning same request
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
commit 5201093ce4b229b3e1b335bdbb37e6376a7c9a21
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