Mount & Blade II: Bannerlord

Mount & Blade II: Bannerlord

Marry Anyone Updated
This topic has been locked
Zarof 24 Feb, 2024 @ 6:23pm
Exspouse duplication bug and subsequent removal message stacking.
Non-crash bug with polygamy and pregnancy+ enabled in settings: Screenshots [imgur.com].

With multiple spouses, there seems to be a logic runaway with the ex-spouse list, first image shows the debug messages from the RemoveExSpouses method in the Helpers.cs file stacking up. Also it seems that the duplicates aren't being removed from the list as they should be per lines 58-61.

I've briefly looked through the code (specifically a find in files via Sublime Text) and it seems the foreach loop in lines 180-183 inside the Patches/PregnancyCampaignBehaviorPatches.cs would cause this ex-spouse stacking issue. If you look at the second image, the list of 4 spouses has multiplied to 39, makes sense that this happened since it's fulfilling the "if (settings.PregnancyPlus)" condition in line 150, then iterating over every exSpouse (which is duplicating every cycle so more and more every time) to run RemoveExSpouse, meaning more debug messages as shown in first image.

Let me know if you want me to test some stuff, afraid I can't do much more with code since I don't know the codebase and C# isn't my wheelhouse...
< >
Showing 1-15 of 18 comments
loste 25 Feb, 2024 @ 11:51am 
What's the fix here? It's getting worryingly long in the duplication list.
Mac Love  [developer] 29 Feb, 2024 @ 6:30am 
Originally posted by Siekaykay:
What's the fix here? It's getting worryingly long in the duplication list.
Still no solution to this problem... :(
YourRealFather 6 Mar, 2024 @ 1:40pm 
I am really looking forward to this fix too. Thanks for carrying on with the mod, Mac. Hopefully you can get it figured out.
whereami 8 Mar, 2024 @ 12:13am 
yeah, it's not a crash bug but still make this mod not perfect. Hopefully someone can fix it in the future
Cicero 18 Mar, 2024 @ 11:02am 
My saved game is trash:(
BurningFalcon 29 Mar, 2024 @ 12:13pm 
If there's a way to fix this, that would be really great.

Also, I'm not sure if my characters are just not that fertile or something, because I had them spend days and nights together and nothing happened.

Ultimately used a console command, but that only got my player-character pregnant.
I want to get all my wives pregnant, to make sure I can have a child of each faction, or something like that.
Gonna make the new true Calradian Empire!!! (and I simply don't know if this error will either break the game at some point due it's endlessly multiplying entries, or because of something else linked to it)


Even if it's a fix we have to apply somewhere else, to just, reduce the list occasionly.
Last edited by BurningFalcon; 29 Mar, 2024 @ 12:13pm
BurningFalcon 31 Mar, 2024 @ 5:32am 
Originally posted by Zarof:
Non-crash bug with polygamy and pregnancy+ enabled in settings: Screenshots [imgur.com].

With multiple spouses, there seems to be a logic runaway with the ex-spouse list, first image shows the debug messages from the RemoveExSpouses method in the Helpers.cs file stacking up. Also it seems that the duplicates aren't being removed from the list as they should be per lines 58-61.

I've briefly looked through the code (specifically a find in files via Sublime Text) and it seems the foreach loop in lines 180-183 inside the Patches/PregnancyCampaignBehaviorPatches.cs would cause this ex-spouse stacking issue. If you look at the second image, the list of 4 spouses has multiplied to 39, makes sense that this happened since it's fulfilling the "if (settings.PregnancyPlus)" condition in line 150, then iterating over every exSpouse (which is duplicating every cycle so more and more every time) to run RemoveExSpouse, meaning more debug messages as shown in first image.

Let me know if you want me to test some stuff, afraid I can't do much more with code since I don't know the codebase and C# isn't my wheelhouse...

Question: you're talking about helpers.cs and Patches/PregnancyCampaignBehaviorPatches.cs

Where can those be found?

I figured out where the mod is downloaded (which is not in the MB-Folder, but in steamapps/workshops.

But neither there, nor in Documents/MB2B or the steamapps/common/MB2B folder, I could find those files.

So even if I would want to check the files/lines you mentioned, I can't because I can't find them.
Last edited by BurningFalcon; 31 Mar, 2024 @ 5:33am
Sly 1 Apr, 2024 @ 1:19pm 
Originally posted by BurningFalcon:
So even if I would want to check the files/lines you mentioned, I can't because I can't find them.

Look at the github page for the mod
BurningFalcon 1 Apr, 2024 @ 3:10pm 
Originally posted by Sly:
Originally posted by BurningFalcon:
So even if I would want to check the files/lines you mentioned, I can't because I can't find them.

Look at the github page for the mod
I feel kinda stupid now.


Anyhow, I wrote a real long text here, and accidentally deleted it....

Sadly, I don't have that much knowledge of programming, I learned some over 10y ago in school, even C#, but we probably only scraped the surface.

But what I think is kinda strange: PregnancyCampaignBehavior looks pregnancy+ and polyamory,
while RomanceCampaignBehavior only looks for polygamy.

The problem however, occurs with the combination of pregnancy+ and polygamy.

What's also strange, I never was able to get any of the characters pregnant, and had to use a console command to do that instead, but this will only make the player-character pregnant, didn't test it further, but the "father" seems to be my first wife. - The child recognizes the parents by a singly entry, that's good.


If this helps in anyway:
I tried to change settings after the mess already occured:
Starting with preg+gamy.
Removing polygamy: keeps duplicating
Set polygamy, remove pregnancy: no duplicating
set polyamory: no duplicating
remove polygamy: still no duplicating
set pregnancy: duplicating (which makes sense, because the container/lists already exist.

I now activated debug, and it only adds the line you'd expect: "Removed duplicate spouse NameOfSpouse"
So the mod thinks it did the job, or at least, the code forces it to say that.


I tried to have ChatGPT look at the code, but it only said to look certain things if they're used correctly, hoped it would find a specific logical error.
But maybe it's worth looking at that?


ChatGPT:
"Null check for hero.Spouse: In the RemoveExSpouses method, there is an attempt to use hero.Spouse without first checking if it's null. Make sure to ensure that hero.Spouse is not null before accessing it.

Usage of the ! operator: In some parts of the code, the ! operator is used, indicating that a certain method or property cannot be null. Make sure that the usage of the ! operator is correct and that the corresponding objects cannot actually be null.

Assignment of _exSpousesList and ExSpousesReadOnlyList: The assignments of _exSpousesList and ExSpousesReadOnlyList to _exSpouses(hero) and ExSpouses(hero) are performed within a condition where hero might be null. Make sure hero is valid before making these assignments."
Sly 2 Apr, 2024 @ 8:20am 
> I now activated debug, and it only adds the line you'd expect: "Removed duplicate spouse NameOfSpouse"
So the mod thinks it did the job, or at least, the code forces it to say that.


Assuming that it's a failure to remove the spouse (and not that there are multiple attempts, some of which fail and some that don't), you can try looking for the line of code that prints : "Removed duplicate spouse NameOfSpouse", and go backwards from it to see what the conditions are for it to be printed/what is supposed to occur before it prints. (as those are failing, but it's still going through them, considering them completed, then printing)
rJay 24 May, 2024 @ 3:54pm 
FYI
ExSpouses, at least in my game, will never pass the not null check in Helpers.cs (line 100).
I added a debug message and in all iteration was always false for that condition.
rJay 24 May, 2024 @ 4:17pm 
Originally posted by Sly:
> I now activated debug, and it only adds the line you'd expect: "Removed duplicate spouse NameOfSpouse"
So the mod thinks it did the job, or at least, the code forces it to say that.


Assuming that it's a failure to remove the spouse (and not that there are multiple attempts, some of which fail and some that don't), you can try looking for the line of code that prints : "Removed duplicate spouse NameOfSpouse", and go backwards from it to see what the conditions are for it to be printed/what is supposed to occur before it prints. (as those are failing, but it's still going through them, considering them completed, then printing)
I'm no expert of C# but I don't think that's what the code is saying.

NB: ALL BELOW IS AN ASSUMPTION SINCE I"M NO EXPERT OF C#

I believe that the problem lies in line 56, where by doing a Distinct() toList() you are no longer referencing hero.ExSpouses, but you created a new List, and every add/remove is done to the new list, not the original one since the reference is lost.
The code is removing the ex, but only on the new list.
Then in line 100 the first check passes, but ExSpouses is never not null (in my case).
This means that neither _exSpouses(hero) nor ExSpouses(hero) will ever be updated.
The log is not misleading, the problem is that there is no update to the original list


I believe that by adding this under line 62 should do the trick, at least for the short testing i've done
if (_exSpouses != null)
{
_exSpouses(hero) = _exSpousesList;
}
Kaineswiftblade 13 Jun, 2024 @ 2:13pm 
Have you gotten those lines of code to work?
Wiegraf Folles 13 Jun, 2024 @ 5:23pm 
Originally posted by rJay:
Originally posted by Sly:
> I now activated debug, and it only adds the line you'd expect: "Removed duplicate spouse NameOfSpouse"
So the mod thinks it did the job, or at least, the code forces it to say that.


Assuming that it's a failure to remove the spouse (and not that there are multiple attempts, some of which fail and some that don't), you can try looking for the line of code that prints : "Removed duplicate spouse NameOfSpouse", and go backwards from it to see what the conditions are for it to be printed/what is supposed to occur before it prints. (as those are failing, but it's still going through them, considering them completed, then printing)
I'm no expert of C# but I don't think that's what the code is saying.

NB: ALL BELOW IS AN ASSUMPTION SINCE I"M NO EXPERT OF C#

I believe that the problem lies in line 56, where by doing a Distinct() toList() you are no longer referencing hero.ExSpouses, but you created a new List, and every add/remove is done to the new list, not the original one since the reference is lost.
The code is removing the ex, but only on the new list.
Then in line 100 the first check passes, but ExSpouses is never not null (in my case).
This means that neither _exSpouses(hero) nor ExSpouses(hero) will ever be updated.
The log is not misleading, the problem is that there is no update to the original list


I believe that by adding this under line 62 should do the trick, at least for the short testing i've done
if (_exSpouses != null)
{
_exSpouses(hero) = _exSpousesList;
}

Which file do you need to add this code and have you had success in your tests by making this change?
Cicero 15 Jun, 2024 @ 2:08pm 
Originally posted by Wiegraf Folles:
Originally posted by rJay:
I'm no expert of C# but I don't think that's what the code is saying.

NB: ALL BELOW IS AN ASSUMPTION SINCE I"M NO EXPERT OF C#

I believe that the problem lies in line 56, where by doing a Distinct() toList() you are no longer referencing hero.ExSpouses, but you created a new List, and every add/remove is done to the new list, not the original one since the reference is lost.
The code is removing the ex, but only on the new list.
Then in line 100 the first check passes, but ExSpouses is never not null (in my case).
This means that neither _exSpouses(hero) nor ExSpouses(hero) will ever be updated.
The log is not misleading, the problem is that there is no update to the original list


I believe that by adding this under line 62 should do the trick, at least for the short testing i've done
if (_exSpouses != null)
{
_exSpouses(hero) = _exSpousesList;
}

Which file do you need to add this code and have you had success in your tests by making this change?

I THINK THE OWNER OF THE MOD HAS NOT BEEN UPDATED YET
< >
Showing 1-15 of 18 comments
Per page: 1530 50