Relentless Purgatory "Could not get new name" NameGenerator Error

Started by Basker_ville, May 17, 2022, 05:48:49 PM

Previous topic - Next topic

Basker_ville

I'm baffled by this NameGenerator bug that's been flinging red errors at me like crazy. Please help.

General properties of this error:
-Red Error: Could not get new name (first rule pack: *exampleRulePackDef*)
   just an example; specific error listed below
-Occurs when PawnKindDefs which use custom NameMakers are spawned
   (RulePackDefs referenced in either CultureDefs or PawnKindDefs)
   Using the nameMaker in Humanoid Alien Races worked fine with no errors
-Typically does not present until after >60 pawns have been generated.
-After the point when it first presents, it then presents a lot (after most following spawns).
-Occurs after debug action Spawns and debug action Executed Raids
-Does not usually prevent the proper naming of the newly spawned unit.
   The error is possibly in the web of relations a pawn is generated with?
   After disabling initial non-family relations in the PawnKindDef, the error still persists.
   After disabling all relationSettings in Humanoid Alien Races ThingDef_AlienRace, still errors.
      relationSettings doesn't include slaves.
-Sometimes the same error occurs multiple times per spawn
-The error frequently references RulePackDefs for previously spawned units rather than for the current unit spawned
   
Steps to replicate this error:
1. Have a PawnKindDef with a custom NameMaker and RulePackDef
2. New map
3. Debugmode ==> Spawn PawnKindDef around 60x (more or less)
or
3. Debugmode ==> Execute Raid > 10000 points (with the relevant faction)

Background:
I discovered this error while working on a mod that adds several races (using Humanoid Alien Races) and factions. When I produced RulePackDefs in order to give each faction their own NameMakers I became trapped in purgatory. First I tied the NameMaker to a custom CultureDef corresponding to a FactionDef. To try and escape the red errors I did away with the CultureDefs and tried using the nameMaker tag in PawnKindDef, but that was no escape at all.

I thought maybe there was something wrong with choosing the right name for the right gender, so I tried limiting it to just one NameMaker. Just the same errors.

I thought there was a problem with my RulePackDef or my namelist.txt, so I tried simplifying it so that the <rulesStrings> was simply <li>r_name->Example Name</li>. No dice, only errors, and now occurring after just the first spawn). That led me to think that the length of the string file .txt had something to do with it and I made a new file 2000 lines long. That too just gave more errors per spawn.

After trying a lot of other things I checked if the error was also present in the reference mods I used for making my RulePackDefs (one of which was a samurai faction mod). It was. I decided to report this error with this samurai mod instead of the one I'm working on because it seems to be the same exact error, it's already on the Steam workshop, and this modlist rules out a few other mods as possible conflicts. I set my modlist as:

Harmony
Core
Royalty
Ideology
HugsLib
Slave Outfits [1.3] (usgiyi.slaveoutfits)
Faction Samurai (qux.factionsamurais)

I used debugmode to spawn samurai. After the 66th spawn I was greeted again by this demonic error:

Stacktrace:
Could not get new name (first rule pack: nomsamuraif)
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Verse.Log:Error (string)
RimWorld.NameGenerator:GenerateName (Verse.Grammar.GrammarRequest,System.Predicate`1<string>,bool,string,string)
RimWorld.NameGenerator:GenerateName (Verse.RulePackDef,System.Predicate`1<string>,bool,string,string)
RimWorld.PawnBioAndNameGenerator:NameResolvedFrom (Verse.RulePackDef,string)
RimWorld.PawnBioAndNameGenerator:GenerateFullPawnName (Verse.ThingDef,Verse.RulePackDef,RimWorld.Pawn_StoryTracker,Verse.RulePackDef,RimWorld.CultureDef,Verse.Gender,RimWorld.PawnNameCategory,string)
RimWorld.PawnBioAndNameGenerator:GeneratePawnName (Verse.Pawn,RimWorld.NameStyle,string)
RimWorld.PawnBioAndNameGenerator:GiveShuffledBioTo (Verse.Pawn,RimWorld.FactionDef,string,System.Collections.Generic.List`1<RimWorld.BackstoryCategoryFilter>,bool)
RimWorld.PawnBioAndNameGenerator:GiveAppropriateBioAndNameTo (Verse.Pawn,string,RimWorld.FactionDef,bool)
Verse.PawnGenerator:TryGenerateNewPawnInternal (Verse.PawnGenerationRequest&,string&,bool,bool)
Verse.PawnGenerator:GenerateNewPawnInternal (Verse.PawnGenerationRequest&)
Verse.PawnGenerator:GenerateOrRedressPawnInternal (Verse.PawnGenerationRequest)
Verse.PawnGenerator:GeneratePawn (Verse.PawnGenerationRequest)
Verse.PawnGenerator:GeneratePawn (Verse.PawnKindDef,RimWorld.Faction)
Verse.DebugToolsSpawning/<>c__DisplayClass1_0:<SpawnPawn>b__1 ()
Verse.DebugTool:DebugToolOnGUI ()
Verse.DebugTools:DebugToolsOnGUI ()
RimWorld.UIRoot_Play:UIRootOnGUI ()
(wrapper dynamic-method) Verse.Root:Verse.Root.OnGUI_Patch1 (Verse.Root)


Hugslib Log:
Log uploaded on Tuesday, May 17, 2022, 2:20:37 PM
Loaded mods:
Harmony(brrainz.harmony)[mv:1.3.0.0]: 0Harmony(2.2.1), HarmonyMod(1.3.0)
Core(Ludeon.RimWorld): (no assemblies)
Royalty(Ludeon.RimWorld.Royalty): (no assemblies)
Ideology(Ludeon.RimWorld.Ideology): (no assemblies)
HugsLib(UnlimitedHugs.HugsLib)[ov:9.0.1]: 0Harmony(av:2.2.1,fv:1.2.0.1), HugsLib(av:1.0.0,fv:9.0.1)
Slave Outfits [1.3](Usgiyi.SlaveOutfits): (no assemblies)
Faction Samurai(qux.factionsamurais): (no assemblies)

Active Harmony patches:
DebugWindowsOpener.DevToolStarterOnGUI: TRANS: HugsLib.Patches.DevToolStarterOnGUI_Patch.ExtendButtonsWindow
DebugWindowsOpener.DrawButtons: TRANS: HugsLib.Patches.DebugWindowsOpener_Patch.DrawAdditionalButtons
Dialog_Options.DoWindowContents: TRANS: HugsLib.Patches.Dialog_Options_Patch.ReplaceModOptionsButton
EditWindow_Log.DoMessagesListing: PRE: HugsLib.Patches.EditWindow_Log_Patch.ExtraLogWindowButtons
Game.DeinitAndRemoveMap: post: HugsLib.Patches.Game_DeinitAndRemoveMap_Patch.MapRemovalHook
Game.FillComponents: PRE: HugsLib.Patches.Game_FillComponents_Patch.GameInitializationHook
Game.FinalizeInit: post: HugsLib.Patches.Game_FinalizeInit_Patch.WorldLoadedHook
LanguageDatabase.SelectLanguage: PRE: HugsLib.Patches.LanguageDatabase_Patch.ForceRestartAfterLangChange
Map.ConstructComponents: post: HugsLib.Patches.Map_ConstructComponents_Patch.MapComponentsInitHook
Map.FinalizeInit: post: HugsLib.Patches.Map_FinalizeInit_Patch.MapLoadedHook
MapComponentUtility.MapGenerated: post: HugsLib.Patches.MapComponentUtility_MapGenerated_Patch.MapGeneratedHook
ModsConfig.RestartFromChangedMods: PRE: HugsLib.Patches.ModsConfig_RestartFromChangedMods_Patch.QuickRestartInDevMode
PlayDataLoader.DoPlayLoad: post: HugsLib.Patches.PlayDataLoader_Patch.InitModsHook
Root.OnGUI: post: HugsLib.Patches.Root_OnGUI_Patch.OnGUIHookUnfiltered
Root.Update: post: HugsLib.Patches.Root_Patch.UpdateHook
Root_Play.SetupForQuickTestPlay: TRANS: HugsLib.Patches.RootPlay_TestPlay_Patch.InjectCustomQuickstartSettings
UIRoot.UIRootOnGUI: post: HugsLib.Patches.UIRoot_OnGUI_Patch.OnGUIHook
VersionControl.DrawInfoInCorner: post: HarmonyMod.VersionControl_DrawInfoInCorner_Patch.Postfix
Harmony versions present: 2.2.1.0: net.pardeike.rimworld.lib.harmony; 2.1.0.0: UnlimitedHugs.HugsLib

Platform information: (hidden, use publishing options to include)

Log file contents:
Mono path[0] = '[Rimworld_dir]/RimWorldWin64_Data/Managed'
Mono config path = '[Rimworld_dir]/MonoBleedingEdge/etc'
Initialize engine version: 2019.4.30f1 (e8c891080a1f)
[Subsystems] Discovering subsystems at path [Rimworld_dir]/RimWorldWin64_Data/UnitySubsystems
GfxDevice: [Renderer information redacted]
Begin MonoManager ReloadAssembly
D3D11 device created for Microsoft Media Foundation video decoding.
Command line arguments: -savedatafolder=C:\Users\User\AppData\LocalLow\Ludeon Studios\RimWorld by Ludeon Studios
RimWorld 1.3.3326 rev562
Save data folder overridden to C:\Users\User\AppData\LocalLow\Ludeon Studios\RimWorld by Ludeon Studios
[HugsLib] version 9.0.1
RandomElementByWeight with totalWeight=0 - use TryRandomElementByWeight.
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

RandomElementByWeight with totalWeight=0 - use TryRandomElementByWeight.
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

Unloading 5 Unused Serialized files (Serialized files now loaded: 2)

Unloading 58 unused Assets to reduce memory usage. Loaded Objects now: 16412.
Total: 143.099400 ms (FindLiveObjects: 0.627700 ms CreateObjectMapping: 0.241500 ms MarkObjects: 142.138700 ms  DeleteObjects: 0.091200 ms)

Unloading 3 Unused Serialized files (Serialized files now loaded: 2)

Unloading 20 unused Assets to reduce memory usage. Loaded Objects now: 16707.
Total: 152.081000 ms (FindLiveObjects: 0.631800 ms CreateObjectMapping: 0.340100 ms MarkObjects: 151.036200 ms  DeleteObjects: 0.072600 ms)

Initializing new game with mods:
  - brrainz.harmony
  - Ludeon.RimWorld
  - Ludeon.RimWorld.Royalty
  - Ludeon.RimWorld.Ideology
  - UnlimitedHugs.HugsLib
  - Usgiyi.SlaveOutfits
  - qux.factionsamurais
Unloading 0 Unused Serialized files (Serialized files now loaded: 2)

Unloading 0 unused Assets to reduce memory usage. Loaded Objects now: 20453.
Total: 186.515200 ms (FindLiveObjects: 0.865100 ms CreateObjectMapping: 0.418400 ms MarkObjects: 185.191300 ms  DeleteObjects: 0.040000 ms)

Could not get new name (first rule pack: nomsamuraif)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

Unloading 3 Unused Serialized files (Serialized files now loaded: 2)

Unloading 3618 unused Assets to reduce memory usage. Loaded Objects now: 17671.
Total: 150.662700 ms (FindLiveObjects: 1.026000 ms CreateObjectMapping: 0.475300 ms MarkObjects: 145.310400 ms  DeleteObjects: 3.850400 ms)

Unloading 0 Unused Serialized files (Serialized files now loaded: 2)

Unloading 27 unused Assets to reduce memory usage. Loaded Objects now: 17716.
Total: 163.984900 ms (FindLiveObjects: 0.963100 ms CreateObjectMapping: 0.752700 ms MarkObjects: 162.072500 ms  DeleteObjects: 0.196000 ms)

Unloading 3 Unused Serialized files (Serialized files now loaded: 2)

Unloading 2 unused Assets to reduce memory usage. Loaded Objects now: 17840.
Total: 156.602900 ms (FindLiveObjects: 0.735500 ms CreateObjectMapping: 0.314300 ms MarkObjects: 155.483700 ms  DeleteObjects: 0.068900 ms)

Initializing new game with mods:
  - brrainz.harmony
  - Ludeon.RimWorld
  - Ludeon.RimWorld.Royalty
  - Ludeon.RimWorld.Ideology
  - UnlimitedHugs.HugsLib
  - Usgiyi.SlaveOutfits
  - qux.factionsamurais
Unloading 0 Unused Serialized files (Serialized files now loaded: 2)

Unloading 1 unused Assets to reduce memory usage. Loaded Objects now: 21937.
Total: 191.441200 ms (FindLiveObjects: 0.924000 ms CreateObjectMapping: 0.470000 ms MarkObjects: 189.974100 ms  DeleteObjects: 0.072800 ms)

Could not get new name (first rule pack: nomsamuraif)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

Could not get new name (first rule pack: nomsamuraif)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

Could not get new name (first rule pack: nomsamuraif)
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)




Don't know what else to do. Just at a loss.

RawCode

1 dnspy (or any other disassembler you like)
2 string search or similar command
3 "Could not get new name"
4 check conditions that cause that specific error string to appear
5 insert trace\debug output directly into classes, or implement runtime patch, or setup debugger

after that you will be able to discover exact cause of that issue and will be able to solve it in efficient manner

special note, it's possible to invoke methods that are not directly related to unity without starting the game, this require some (a lot actually) work to setup, but really useful for errors like this.


Basker_ville

Yes I've been looking through a bunch of classes connected to the web of name generation. The source of the error message is in the NameGenerator class. The relevant section is toward the end of this block:


public static string GenerateName(GrammarRequest request, Predicate<string> validator = null, bool appendNumberIfNameUsed = false, string rootKeyword = null, string untranslatedRootKeyword = null)
{
if (untranslatedRootKeyword == null)
{
untranslatedRootKeyword = rootKeyword;
}
string text = "ErrorName";
if (appendNumberIfNameUsed)
{
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 5; j++)
{
text = GenText.CapitalizeAsTitle(GrammarResolver.Resolve(rootKeyword, request, null, false, untranslatedRootKeyword, null, null, true));
if (i != 0)
{
text = text + " " + (i + 1);
}
if (validator == null || validator(text))
{
return text;
}
}
}
return GenText.CapitalizeAsTitle(GrammarResolver.Resolve(rootKeyword, request, null, false, untranslatedRootKeyword, null, null, true));
}
for (int k = 0; k < 150; k++)
{
text = GenText.CapitalizeAsTitle(GrammarResolver.Resolve(rootKeyword, request, null, false, untranslatedRootKeyword, null, null, true));
if (validator == null || validator(text))
{
return text;
}
}
Log.Error("Could not get new name (first rule pack: " + request.Includes.FirstOrDefault<RulePackDef>().ToStringSafe<RulePackDef>() + ")");
return text;
}


I'm still trying to make sense of what I'm looking at and how exactly it ties together. The Log.Error() seems to be triggered after a few different commands: two if-statements and then a for-loop.
I guess that error is reached when the preceding bits of code fail?

I've no idea how to do anything in your 5th point. Could you point me toward some kind of tutorial or example for one of those things?

RawCode

probably this will work for you:
https://www.youtube.com/watch?v=rgPapHIm-5A

"portable" method is
https://harmony.pardeike.net/articles/intro.html

as for trace output, this is not something that can be explained, it's just no way to explain why in that specific case you should log "request" and move to very top where "request" is created and log why exactly "request" created this way.
it's just like not possible to explain why exactly i made this post this way.