Skip to content

Commit

Permalink
Add extra code to attempt to ensure rel population properly ends
Browse files Browse the repository at this point in the history
  • Loading branch information
soopercool101 committed Sep 25, 2024
1 parent c93d5ae commit b727bb8
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions BrawlLib/SSBB/ResourceNodes/Modules/RELNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace BrawlLib.SSBB.ResourceNodes
Expand Down Expand Up @@ -297,6 +298,27 @@ public byte? ItemID4

public override void Dispose()
{
if (!Populated)
{
int timeoutSecs = 5;
// wait 5 seconds to see if population finishes
while (!Populated && timeoutSecs >= 0)
{
Thread.Sleep(1000);
--timeoutSecs;
}
// attempt to cancel population if it hasn't finished still
if (!Populated)
{
populator.CancelAsync();
for (int i = 0; i < 5; i++) // wait 5 more seconds for cancellation to finish hopefully
{
Thread.Sleep(1000);
}
Debug.WriteLine("Cancelled population");
}
}
populator?.Dispose();
_files.Remove(ModuleID);
base.Dispose();
}
Expand Down Expand Up @@ -445,18 +467,21 @@ public override void OnPopulate()
}
}
}

Sections[5].Populate();

watch.Stop();
Console.WriteLine("Took {0} seconds to relocate {1} module", watch.ElapsedMilliseconds / 1000d, Name);
};

using (BackgroundWorker b = new BackgroundWorker())
Populated = false;
populator = new BackgroundWorker();
populator.WorkerSupportsCancellation = true;
populator.RunWorkerCompleted += (sender, args) =>
{
b.DoWork += new DoWorkEventHandler(work);
b.RunWorkerAsync();
}
Populated = true;
};
populator.DoWork += new DoWorkEventHandler(work);
populator.RunWorkerAsync();

// Stage module conversion
byte* bptr = (byte*) WorkingUncompressed.Address;
Expand Down Expand Up @@ -493,6 +518,9 @@ public override void OnPopulate()
UpdateItemIDs();
}

private BackgroundWorker populator;
public bool Populated = false;

public void ApplyRelocations()
{
foreach (ModuleSectionNode r in Sections)
Expand Down

0 comments on commit b727bb8

Please sign in to comment.