Fix race conditions with slide textures loading

This commit is contained in:
Damián Garro 2022-09-13 19:30:23 -03:00
parent 073892c008
commit 5aba437596

View File

@ -4,8 +4,8 @@ using NewHorizons.Utility;
using OWML.Common;
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using static NewHorizons.External.Modules.PropModule;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Builder.Props
{
@ -113,13 +113,10 @@ namespace NewHorizons.Builder.Props
slideCollection.slides[index]._image = ImageUtilities.Invert(tex);
// Track the first 15 to put on the slide reel object
if (index < 15)
if (index < textures.Length)
{
textures[index] = tex;
displaySlidesLoaded++; // threading moment
}
if (displaySlidesLoaded >= textures.Length)
if (Interlocked.Increment(ref displaySlidesLoaded) == textures.Length)
{
// all textures required to build the reel's textures have been loaded
var slidesBack = slideReelObj.transform.Find("Props_IP_SlideReel_7/Slides_Back").GetComponent<MeshRenderer>();
@ -133,6 +130,7 @@ namespace NewHorizons.Builder.Props
slidesFront.material.SetTexture(EmissionMap, reelTexture);
}
}
}
);
// Else when you put them down you can't pick them back up
@ -352,9 +350,8 @@ namespace NewHorizons.Builder.Props
(Texture2D tex, int index) =>
{
slideCollection.slides[index]._image = tex;
displaySlidesLoaded++; // threading moment
if (displaySlidesLoaded >= slides.Length)
if (Interlocked.Increment(ref displaySlidesLoaded) == slides.Length)
{
mindSlideProjector.enabled = true;
visionBeamEffect.SetActive(true);