边缘世界 RimWorld

边缘世界 RimWorld

MIM - WH40k Core
Console error spam when allowed gene/xenotype list is empty (no crash)
When a pawn receives a xenotype via HediffComp_GiveXenotype, the game outputs repeated red errors if the race/pawnkind has no allowed genes/xenotypes defined. The game does not crash, but the errors spam the log every tick (or tick interval), hurting performance and obscuring other issues.

Observed error (excerpt):
At least one allowed gene requires to avoid error.
[Prepatcher, 0Harmony.dll] ...
[MIM - WH40k Core, MIM40kFactions1.6.dll] MIM40kFactions.Utility_GeneRestriction.CanAddGenetoPawnKind(Verse.GeneDef gene, Verse.Pawn pawn)
[MIM - WH40k Core, MIM40kFactions1.6.dll] MIM40kFactions.HarmonyPatches.EMWH_GeneRestrictionPatch.AddGenetoKindPrefix(Verse.Gene gene, Verse.Pawn ___pawn)
...
[MIM - WH40k Core, MIM40kFactions1.6.dll] MIM40kFactions.HediffComp_GiveXenotype.CompPostTickInterval(...)

Steps to reproduce:

Ensure a pawn gets HediffComp_GiveXenotype (e.g., WH40k faction spawn or scripted hediff).

Use a race/pawnkind whose AllowedGenes / AllowedXenotypes is empty (or not defined).

Start the game: the console fills with the error every tick/interval.

Actual behavior:
Non-fatal but continuous console errors; log spam degrades performance and makes debugging difficult.

Expected behavior:
If there are no allowed genes/xenotypes, skip gene assignment silently (or emit a single warning once) instead of logging an error every tick.

Suggested fix (examples):

Guard in Utility_GeneRestriction.CanAddGenetoPawnKind or in EMWH_GeneRestrictionPatch.AddGenetoKindPrefix:
if (allowedGenes == null || !allowedGenes.Any())
return false; // do not log an error, just skip

If you want visibility, log once per pawn (e.g., store a HashSet of notified pawn IDs) or switch to a Warning level, not every tick.

In HediffComp_GiveXenotype, consider short-circuiting when restrictions block all genes, to avoid repeated attempts each interval.

Environment:

MIM – WH40k Core (MIM40kFactions1.6.dll) with Biotech.

No hard crash; pure console spam.

Temporary workarounds for players:

Disable gene restrictions in mod settings (if available), or

Patch in at least one harmless allowed gene/xenotype for the affected race/pawnkind.

Thanks!

Copied from GPT:)