ExceptionInspector throws NullReferenceException every frame when a patch method belongs to no mod (dynamic assembly)

Ouverte Adaptée aux débutants
#7 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
76/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
csharp
Domaine
game-dev

Piste de recherche

Commencez par Mods.AddMetadata, puis suivez la manière dont ExceptionInfo.GetReport crée les détails du mod et dont Columns.Column utilise leurs métadonnées. Reproduisez le problème avec une méthode de patch Harmony provenant d’un assembly dynamique et une exception qui passe par celle-ci. Le travail sera terminé lorsque l’ouverture de l’inspecteur ne déclenchera plus d’exceptions répétées pour les patches sans métadonnées de mod.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Summary

When a captured exception has a stack frame whose method carries a Harmony patch from an assembly that no mod owns (for example a runtime-generated assembly), the inspector window throws a NullReferenceException on every frame. The log fills with thousands of errors and the window cannot be used.

Seen with Visual Exceptions 1.5.0.0 on RimWorld 1.7.5005, Harmony 3.

Cause

Mods.AddMetadata creates a ModInfo for every patch method, also when GetModMetaData(assembly) returns null:

static IEnumerable<ModInfo> AddMetadata(IEnumerable<MethodInfo> methods)
{
    return methods.Select(method =>
    {
        var assembly = method.DeclaringType.Assembly;
        var metaData = GetModMetaData(assembly);
        return new ModInfo { method = method, metaData = metaData };
    });
}

ExceptionInfo.GetReport then adds an ExceptionDetails.Mod with meta == null, and Columns.Column(this ExceptionDetails.Mod mod) dereferences it:

var name = mod.meta.Name.Truncate(200, truncatedModNamesCache);

Stack frames do not have this problem, because GetMetadataIfMod returns null for non-mod code and GetAllMethods skips those. Only patches are missing the check.

How it showed up

A player ran the Overclock mod with "Parallel pawn ticks (experimental)" on. That feature builds its prefix classes at runtime with AssemblyBuilder.DefineDynamicAssembly (types named IdPrefix_<n>_<method> and IdState_<n>) and patches thousands of mod methods with them. Those types are in no mod's loadedAssemblies.

During loading, another mod requested a graphic with a null texture path, which throws ArgumentNullException in ContentFinder<Texture2D>.Get. One frame of that exception had such a generated prefix on it. Once the inspector opened at the main menu:

Exception filling window for VisualExceptions.ExceptionInspector: System.NullReferenceException: Object reference not set to an instance of an object.
   at VisualExceptions.Columns.Column_Patch1(Mod mod)
   at VisualExceptions.ExceptionInspector.<>c.<DoWindowContents>b__9_2(Mod mod)
   at System.Linq.Enumerable.ListSelectIterator`2.MoveNext()
   at System.Linq.Enumerable.MaxFloat[TSource,TResult](IEnumerable`1 source, Func`2 selector)
   at VisualExceptions.Columns.MaxWidth(IEnumerable`1 drawers)
   at VisualExceptions.ExceptionInspector.DoWindowContents_Patch1(ExceptionInspector this, Rect inRect)
   at Verse.Window.InnerWindowOnGUI_Patch3(Window this, Int32 x)

This repeated 2,515 times in under a minute.

Steps to reproduce

  1. Have any Harmony patch whose patch method is declared in a dynamic assembly, on a method of a mod.
  2. Throw an exception that passes through that method and is caught by one of the handlers Visual Exceptions instruments.
  3. Open the inspector.
Langage dominant
C#
Étoiles
10
Forks
2
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.