Fix null reference on missing hybrid def

This commit is contained in:
lutepickle 2022-04-27 17:34:19 -07:00
parent 9e374f3350
commit 7a58d3ed3b
3 changed files with 8 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;