Skip to content

🗲 Crashes 🗲

NullReferenceException

Message: Object reference not set to an instance of an object.

Source: SandBox
GetSuitableSpear - PrepareGuardAgentDataFromGarrison - TakeGuardAgentFromGarrisonTroopList - CreateStandGuardWithSpear

I'm getting this crash whenever I take a settlement with my custom culture and try to go to Lord's hall or dungeon
REASON: Custom culture guards entries in spgenericcharacters.xml (sandbox folder) need to go in spnpcharacters.xml in your mod's folder

Source: TaleWorlds.CampaignSystem
CampaignObjectManager - InitializeCachedData - InitializeOnNewGame - OnInitialize - DoLoadingForGameType

REASON: Settlement bound="Settlement.town_CR4" pointed to the non-existing settlement in settlements.xml

GetHeroesForEffectiveRelation - ApplyInternal - CreateRebelPartyAndClan - StartRebellionEvent - DailyTickSettlement

REASON: ?

BuildWorkshopForHeroAtGameStart - BuildWorkshopsAtGameStart - OnNewGameCreatedPartialFollowUp

REASON: Used non-existant equipment set for NPCCharacter: <EquipmentSet id="npc_gentry_equipment_sturgia"/>

GetBodyProperties - GetCharacterCode - set_Character - set_Troop - PartyCharacterVM - InitializePartyList

REASON: Used non-existant BodyProperty for NPCCharacter

DefaultMapDistanceModel - GetDistance

REASON1: Wrongly assigned Settlement, Kingdom without a settlement. Attach dnSpy, it will show faction.FactionMidSettlement == null. Fix your XML.

REASON2: Problems with Navmesh. Inaccessible settlements. Old/mismatching settlements_distance_cache.bin - fix navmesh, regenerate settlements_distance_cache.bin

CampaignObjectManager.InitializeCachedData()

REASON: settlements.xml error - I accidently deleted one settlement and village had no bounded castle (crash on settlement.OwnerClan.OnBoundVillageAdded(settlement.Village);). This was on new game start.

DefaultMapDistanceModel - GetDistance - VillageGoodProductionCampaignBehavior - DistributeInitialItemsToTowns - OnNewGameCreatedPartialFollowUp

REASON: ??

SpawnNotablesIfNeeded - NotablesCampaignBehavior - DailyTickSettlement

REASON: Some type of notable is missing for some culture. I was missing RuralNotable
Set in <notable_and_wanderer_templates> in culture XML

CalculateAverageWage - DoLoadingForGameType - DoLoadingForGameManager

REASON: ??? (maybe something related to party templates with non-existant troop IDs, but not confirmed)

CharacterObject - GetSkillValue - DefaultPartyMoraleModel - GetMoraleEffectsFromSkill - GetEffectivePartyMorale

REASON: used not existant troop ID in the <MBPartyTemplate id="villager_CUSTOM_CULTURE_template">
HINT: Check Encyclopedia-Troops if necessary troop is actually in the game.

DefaultPartyWageModel - GetTotalWage - MobileParty - get_TotalWage - get_LimitedPartySize - CalculateGarrisonChangeInternal

REASON: Troop ID used in partyTemplates.xml refers to a non-existing troop ID in the trooptree.

SetInitialValuesFromCharacter - CreateNewHero - CreateSpecialHero - CreateMinorFactionHeroFromTemplate - SpawnMinorFactionHeroes - OnNewGameCreated

REASON: spclans.xslt and custom_spclans.xml were in a separate folder for spclans, but missing empty spclans.xml file

HeroCreator - CreateNewHero - FindRandomInternal - CreateNewHero - CreateSpecialHero

REASON: error in XSLT by assigning a culture to a hero

SiegeTowerSpawner - AssignParameters - SpawnerEntityMissionHelper - OnPreInit

On starting the scene.
REASON: name property for siege_tower entity:

<game_entity name="siege_tower_5m_spawner_right" prefab="siege_tower_5m_spawner">
removed name=... solved the crash:
<game_entity prefab="siege_tower_5m_spawner">

ArrangeDestructedMeshes - SetUpScene - AfterStart - FinishMissionLoading

REASON: siege engine can't find which wall segment to attack. Tag is missing. Commented out in xscene:

<game_entity name="easteurope_wall_level_l1_right" old_prefab_name="">
    <flags>
        <flag name="record_to_scene_replay" value="true"/>
    </flags>
    <tags>
        <tag name="right_wall"/>  <--- this was used by siege_engine >
    </tags>
    ...

DestructableComponent - OnInit

The scene was working on L1 Summer/Winter/Sprint, crashing on L1/Fall and on all L2/L3
REASON: entity with DestructableComponent had debris_holder with season_mask="253". Removing the season_mask solved the crash:

<!-- <game_entity name="debris_holder" old_prefab_name="" mobility="1" season_mask="253"> FALL CRASH -->
<game_entity name="debris_holder" old_prefab_name="" mobility="1"> <!-- NO CRASH -->

BackstoryCampaignBehavior - OnNewGameCreated

REASON: commented out some native hard-coded lord/settlement
Check in BackstoryCampaignBehavior.OnNewGameCreated
Fix with Harmony to skip this native code:

[HarmonyPatch(typeof(BackstoryCampaignBehavior))]
[HarmonyPatch("OnNewGameCreated")]
public class BackstoryCampaignBehavior_OnNewGameCreated_Patch
{
    public static bool Prefix()
    {
        return false;
    }
}
CreateNewHero - CreateSpecialHero - OnNewGameCreatedPartialFollowUp - InitialChildGenerationCampaignBehavior

REASON: Hero present, lord not present, lord used in a clan definition as owner

DefaultMapDistanceModel - GetDistance - UpdateFriendshipAndEnemies

REASON 1: Lord/hero without a proper clan (clan not created/deleted)

REASON 2: Incorrect load order when launching game, e.g. Lemmy's map was loaded after a mod using it.

Kingdom - OnNewGameCreated - InvokeList - OnNewGameCreated

REASON: Deleted hero/lord, the 'owner' of the Kingdom

CalculateDailyProductionAmount - GetWerehouseCapacity - TickProductions - OnNewGameCreatedPartialFollowUp

REASON: assigned a settlement to non-existant clan

NameGenerator - CalculateNameScore - SelectNameIndex - GenerateHeroFirstName - CreateSpecialHero - InitialChildGenerationCampaignBehavior - OnNewGameCreatedPartialFollowUp

REASON: Clan's owner was non-existant Lord

DefaultMapDistanceModel - GetClosestSettlementForNavigationMesh - GetDistance - FindNearestSettlement - TryToAssignTradeBoundForVillage - UpdateTradeBounds

REASON: saved a Main_map when game was open, xscene file gone, map gone. Game started with vanilla Main_map with custom settlements.xml

AgingCampaignBehavior - OnHeroComesOfAge - InvokeList - DailyTickHero

REASON: error/missing sandboxcore_equipment_sets.xml for the hero's culture. Hero turned 18

Source: MonoMod.Utils
GauntletMovie - LoadMovie_Patch0 - Load - LoadMovie

REASON: Movie XML file not present. (deleted/wrong name/path?)

LordConversationsCampaignBehavior - conversation_wanderer_introduction_on_condition - RunCondition

REASON: No native settlement town_ES4 in the game.



ArgumentNullException

Message: Value cannot be null. Parameter name: source
Source: System.Core
CreateHeroAtOccupation

REASON: in CUSTOM_culture.xml commented out one name:

<male_names>
    <!-- <name name="Adalbert" /> -->
    <name name="Adalbern" />
also commented out one basic_mercenary_troops:
<basic_mercenary_troops>
    <template name="NPCCharacter.eastern_mercenary" />
    <template name="NPCCharacter.western_mercenary" />
    <!--<template name="NPCCharacter.sword_sisters_sister_t3" /> -->
</basic_mercenary_troops>

SortedList.Add - AiVisitSettlementBehavior - FindSettlementsToVisitWithDistances - AiHourlyTick

An entry with the same key already exists
REASON: had <Village> with the same id in the settlements.xml

Linq.Enumerable.Any - Extensions.IsEmpty - NameGenerator - GetNameListForCulture - GenerateHeroFirstName

REASON: error in the culture xml file



InvalidOperationException

Message: The XmlReader state should be Interactive.
Source: System.Xml.Linq
ReadContentFrom - Load - ToXDocument - MergeTwoXmls - CreateMergedXmlFile

REASON: error in the XML file, example:
- missing opening tag <Items>
- wrong closing tag <Items/> vs </Items>
- CUSTOM_settlements.xml completely empty
- etc

Message: Sequence contains no matching element
Source: System.Core
Enumerable.First - InitializeCaravanOnCreation - CreateCaravanParty - CreateParty - CreateCaravanParty

REASON: CUSTOM_culture notable Merchant was expecting CaravanGuard with the same culture: character.Culture == mobileParty.Party.Owner.Culture

InitializeCaravanOnCreation
CharacterObject characterObject = CharacterObject.All.First((CharacterObject character) => character.Occupation == Occupation.CaravanGuard && character.IsInfantry && character.Level == 26 && character.Culture == mobileParty.Party.Owner.Culture);

Single - CharacterCreationCultureStageVM - SortCultureList - CharacterCreationCultureStageView

REASON: Native culture is removed or is made is_main_culture=true



IndexOutOfRangeException

Message: Index was outside the bounds of the array.
Source: TaleWorlds.CampaignSystem
DefaultMapWeatherModel - GetWeatherEventInPosition - WeatherAudioTick - TickVisuals

REASON: Marked 'Use Dynamic Weather Effects' without the a flowmap. Maybe map is not a square. Maybe flowmap is not 1024x1024.


Source: TaleWorlds.CampaignSystem
OnNewGameCreated

REASON1: Lord (NPCCharacter) id mismatch with hero id, no lord for the heroe, "Hero." missed with hero id

REASON2: 2 lords with the same id

REASON3: Comments in spkingdoms.xml :D

REASON4: NPCCharacter age="9.9" (not int) in lords.xml



AccessViolationException

Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source: TaleWorlds.MountAndBlade
MapScene - GetNavigationMeshCenterPosition - DefaultMapDistanceModel - GetClosestSettlementForNavigationMesh - GetDistance - CalculatePartyInfluenceCost - CalculateTotalInfluenceCost

REASON: CUSTOM_settlements.xml does not match settlements.xml

FinalizeMission - EndMissionInternal - CheckMissionEnd - OnTick

Crash was on the exit out from the mission.
REASON: xscene contained one entity, and commenting it out stopped the crash, no idea why/how, there are more similar entities in the scene:

<game_entity name="aserai_grandbazaar_wall" old_prefab_name="" occlusion_body_name="bo_occ_aserai_grandbazaar_wall">
    <transform position="-73.488, 137.875, 0.924" rotation_euler="0.000, 0.000, 1.571" scale="0.470, 0.150, 0.000"/>
    <physics shape="bo_aserai_grandbazaar_wall"/>
    <components>
        <meta_mesh_component name="aserai_grandbazaar_wall">
            <mesh name="aserai_grandbazaar_wall" material="adobe_wall_white"/>
        </meta_mesh_component>
    </components>
</game_entity>



Reflection.TargetInvocationException

Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
InvokeMethod - Invoke - CreateInstanceImpl - CreateInstance - CreateScreen

REASON: map xscene settlement ID mismatch with settlements.xml settlement ID. settlements.xml has a settlement with ID, which is not present in the xscene file

... GetEncyclopediaPageInstance - SetEncyclopediaPage - GauntletMapEncyclopediaView - ExecuteLink

Crash by pressing on the lord's image in the Encyclopedia.
REASON: Lord's spause is deleted, but reference to it in the heroes.xml remains for the main lord. Eg: spouse="Hero.lord_4_2"


TypeInitializationException

Source: TaleWorlds.CampaignSystem
CalculateBaseSpeed - CalculateSpeedForPartyUnified

More info here


System.Xml.Xsl.XslTransformException

Message: Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added.
Source: System.Data.SqlXml
XmlQueryOutput - ThrowInvalidStateError

REASON: tried to change non-existant attribute with XSLT



CTD without any message

On mission start.
Error log last line: Selected formations being cleared.
REASON: this entity was commented out in the xscene:

<game_entity name="icon_camera" old_prefab_name="icon_camera" mobility="1">




Others

GetBodyProperties - LocationCharacter - CreateMercenary - AddLocationCharacters - AddMercenaryCharacterToTavern

In CUSTOM_culture.xml error in defining caravan guards:

caravan_master="NPCCharacter.caravan_master_sturgia"
armed_trader="NPCCharacter.armed_trader_sturgia"
caravan_guard="NPCCharacter.caravan_guard_sturgia"
veteran_caravan_guard="NPCCharacter.veteran_caravan_guard_sturgia"

HarmonyLib.PatchClassProcessor.ReportException() - Patch()

When loading the game with DnSpy attached, make sure to disable the BannerColorPersistence in the load order.