Fix null reference on missing hybrid def

This commit is contained in:
lutepickle 2022-04-27 17:34:19 -07:00
parent 4896f949ab
commit fffd4f5f00
4 changed files with 9 additions and 4 deletions

Binary file not shown.

View file

@ -492,7 +492,7 @@ namespace RJW_Menstruation
string MotherRaceName = "";
string FatherRaceName = "";
MotherRaceName = mother.kindDef?.race?.defName;
PawnKindDef tmp = spawn_kind_def;
PawnKindDef non_hybrid_kind_def = spawn_kind_def;
if (father != null)
FatherRaceName = father.kindDef?.race?.defName;
@ -507,7 +507,7 @@ namespace RJW_Menstruation
{
if (!Configurations.UseHybridExtention || spawn_kind_def == null)
{
spawn_kind_def = tmp;
spawn_kind_def = non_hybrid_kind_def;
var groups = DefDatabase<RaceGroupDef>.AllDefs.Where(x => !(x.hybridRaceParents.NullOrEmpty() || x.hybridChildKindDef.NullOrEmpty()));

View file

@ -50,9 +50,13 @@ namespace RJW_Menstruation
{
string key = hybridInfo.RandomElementByWeight(x => x.Value).Key;
res = DefDatabase<PawnKindDef>.GetNamedSilentFail(key);
if (res == null) res = DefDatabase<ThingDef>.GetNamedSilentFail(key).race.AnyPawnKind;
if (res == null) res = DefDatabase<ThingDef>.GetNamedSilentFail(key)?.race?.AnyPawnKind;
if (res == null) hybridInfo.Remove(key);
if (res == null)
{
Log.Warning($"Could not find pawnKind or race {key}, removing hybrid definition");
hybridInfo.Remove(key);
}
} while (res == null && !hybridInfo.EnumerableNullOrEmpty());
return res;

View file

@ -1,5 +1,6 @@
Version 1.0.6.1
- Fix error when bleeding rate set to 0.
- Fix errors when a hybrid refers to an invalid race.
- A pawn in estrus will prefer partners and sex types that would result in pregnancy.
- Optional (default disabled) alternative casual hookup settings for a pawn in visible estrus.