Skip to content

Commit

Permalink
fix: #2579 - Weaver skips already weaved assemblies when restarting U…
Browse files Browse the repository at this point in the history
…nity. fixes a bug where GeneratedNetworkCode class would exist twice, while the newer one was missing some writers
  • Loading branch information
miwarnec committed Mar 27, 2021
1 parent afc4f58 commit 3a9d954
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Assets/Mirror/Editor/Weaver/Weaver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Mono.CecilX;

namespace Mirror.Weaver
Expand Down Expand Up @@ -163,6 +164,12 @@ static void CreateGeneratedCodeClass()
WeaverTypes.Import<object>());
}

static bool ContainsGeneratedCodeClass(ModuleDefinition module)
{
return module.GetTypes().Any(td => td.Namespace == GeneratedCodeNamespace &&
td.Name == GeneratedCodeClassName);
}

static bool Weave(string assName, IEnumerable<string> dependencies)
{
using (DefaultAssemblyResolver asmResolver = new DefaultAssemblyResolver())
Expand All @@ -177,6 +184,17 @@ static bool Weave(string assName, IEnumerable<string> dependencies)
asmResolver.AddSearchDirectory(path);
}
}
// fix "No writer found for ..." error
// https://github.com/vis2k/Mirror/issues/2579
// -> when restarting Unity, weaver would try to weave a DLL
// again
// -> resulting in two GeneratedNetworkCode classes (see ILSpy)
// -> the second one wouldn't have all the writer types setup
if (ContainsGeneratedCodeClass(CurrentAssembly.MainModule))
{
//Log.Warning($"Weaver: skipping {CurrentAssembly.Name} because already weaved");
return true;
}

WeaverTypes.SetupTargetTypes(CurrentAssembly);

Expand Down

0 comments on commit 3a9d954

Please sign in to comment.