Skip to content

Commit

Permalink
Fixed an issue with Compatibility Layers getting Garbage Collected wh…
Browse files Browse the repository at this point in the history
…ile still in use
  • Loading branch information
HerpDerpinstine committed Oct 11, 2024
1 parent 0adbf65 commit 107ef73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MelonLoader/CompatibilityLayers/MelonCompatibilityLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal static void LoadModules()
continue;

MelonDebug.Msg($"Loading MelonModule '{m.fullPath}'");
MelonModule.Load(m);
m.moduleGC = MelonModule.Load(m);
}

foreach (var file in Directory.GetFiles(baseDirectory))
Expand Down
9 changes: 9 additions & 0 deletions MelonLoader/Modules/MelonModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using System.Linq;
using System.Reflection;

#if NET6_0_OR_GREATER
using System.Runtime.Loader;
#endif

namespace MelonLoader.Modules
{
/// <summary>
Expand Down Expand Up @@ -53,7 +57,11 @@ internal static MelonModule Load(Info moduleInfo)
Assembly asm;
try
{
#if NET6_0_OR_GREATER
asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(moduleInfo.fullPath);
#else
asm = Assembly.LoadFrom(moduleInfo.fullPath);
#endif
}
catch (Exception ex)
{
Expand Down Expand Up @@ -115,6 +123,7 @@ public class Info
public readonly string fullPath;
internal readonly Func<bool> shouldBeRemoved;
internal readonly Func<bool> shouldBeIgnored;
internal MelonModule moduleGC;

internal Info(string path, Func<bool> shouldBeIgnored = null, Func<bool> shouldBeRemoved = null)
{
Expand Down

0 comments on commit 107ef73

Please sign in to comment.