[solved]md2 mechwall null map error

Started by sulusdacor, January 04, 2018, 11:34:16 AM

Previous topic - Next topic

sulusdacor

trying to get the mechanical walls to work with b18 and they do, but still produce a null map error. i'm unsure why so maybe someone can help me there.

i assume it has sth to do with the genspawn line/section. but since the wall/embrasure spawns the map somehow gets used (which confuses me a lot XD). when i tried the public Map one it did not spawn at all. found the vanilla blueprint.TryReplaceWithSolidThing, which uses a bit similar code. the genspawn seems the same to me and the handling of the map variable too. so probably some lack of understanding sth there on my part and would be nice if someone could point that out to me, sicne i don't see it.

below log and code for all.

log (full output log as attachement):
Constructed TargetInfo with cell=(76, 0, 61) and a null map.
Verse.Log:Warning(String)
Verse.TargetInfo:.ctor(IntVec3, Map, Boolean)
MD2_mechwalls.Building_MechWall:DoDustPuff()
MD2_mechwalls.Building_MechWallExtended:ToggleStateOne()
MD2_mechwalls.Building_MechWallExtended:<GetGizmos>b__2()
Verse.Command_Action:ProcessInput(Event)
Verse.GizmoGridDrawer:DrawGizmoGrid(IEnumerable`1, Single, Gizmo&)
RimWorld.InspectGizmoGrid:DrawInspectGizmoGridFor(IEnumerable`1)
RimWorld.MainTabWindow_Inspect:DrawInspectGizmos()
RimWorld.InspectPaneUtility:ExtraOnGUI(IInspectPane)
RimWorld.MainTabWindow_Inspect:ExtraOnGUI()
Verse.WindowStack:WindowStackOnGUI()
RimWorld.UIRoot_Play:UIRootOnGUI()
Verse.Root:OnGUI()


code (full mod file as attachement, base just adds the research tab):
/*
* Created by SharpDevelop.
* User: sulusdacor
* Date: 31.12.2017
* Time: 22:06
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using RimWorld;
using System;
using UnityEngine;
using Verse;
using Verse.Sound;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace MD2_mechwalls
{
[DefOf]
public static class Keys
{
public static KeyBindingDef BuildingOnOffToggle
{
get
{
return Keys.Named("BuildingOnOffToggle");
}
}

public static KeyBindingDef ExtendMechWall
{
get
{
return Keys.Named("ExtendMechWall");
}
}

public static KeyBindingDef ExtendMechEmbrasure
{
get
{
return Keys.Named("ExtendMechEmbrasure");
}
}

public static KeyBindingDef RecessMechWall
{
get
{
return Keys.Named("RecessMechWall");
}
}

public static KeyBindingDef DeactivateDroid
{
get
{
return Keys.Named("DeactivateDroid");
}
}

public static KeyBindingDef FissureGeneratorChangeFissure
{
get
{
return Keys.Named("FissureGeneratorChangeFissure");
}
}

public static KeyBindingDef Named(string defName)
{
return DefDatabase<KeyBindingDef>.GetNamed(defName, true);
}
}

public class Building_MechWallRecessed : Building_MechWall
{
[CompilerGenerated]
private IEnumerable<Gizmo> FabricatedMethod9()
{
return base.GetGizmos();
}

public override IEnumerable<Gizmo> GetGizmos()
{
Command_Action command_Action = new Command_Action
{
action = delegate
{
this.ToggleStateOne();
},
defaultDesc = Translator.Translate("MD2.MechWallExtendWallDesc"),
defaultLabel = Translator.Translate("MD2.MechWallExtendWallLable"),
activateSound = SoundDef.Named("Click"),
// hotKey = Keys.Named("ExtendMechWall"),
disabled = false,
groupKey = 313740010,
icon = Building_MechWall.ExtendIcon
};
yield return command_Action;
command_Action = new Command_Action
{
action = delegate
{
this.ToggleStateTwo();
},
defaultDesc = Translator.Translate("MD2.MechWallOpenEmbrasureDesc"),
defaultLabel = Translator.Translate("MD2.MechWallOpenEmbrasureLable"),
activateSound = SoundDef.Named("Click"),
// hotKey = Keys.Named("ExtendMechEmbrasure"),
disabled = false,
groupKey = 313740011,
icon = Building_MechWall.EmbrasureIcon
};
yield return command_Action;
if (this.FabricatedMethod9() != null)
{
using (IEnumerator<Gizmo> enumerator = this.FabricatedMethod9().GetEnumerator())
{
while (enumerator.MoveNext())
{
Command command = (Command)enumerator.Current;
yield return command;
}
}
}
yield break;
}

public override void ToggleStateOne()
{
if (base.HasPower)
{
// IntVec3 position = base.Position;
Thing thing = ThingMaker.MakeThing(Building_MechWall.MechWallExtended, this.Stuff);
thing.SetFactionDirect(base.Faction);
thing.HitPoints = this.HitPoints;
Map map = base.Map;
this.Destroy(0);
this.DoDustPuff();
GenSpawn.Spawn(thing, Position, map, Rotation);
}
}

public override void ToggleStateTwo()
{
if (base.HasPower)
{
// IntVec3 position = base.Position;
Thing thing = ThingMaker.MakeThing(Building_MechWall.MechWallEmbrasure, this.Stuff);
thing.SetFactionDirect(base.Faction);
thing.HitPoints = this.HitPoints;
Map map = base.Map;
this.Destroy(0);
this.DoDustPuff();
GenSpawn.Spawn(thing, Position, map, Rotation);
}
}
}

public class Building_MechWallExtended : Building_MechWall
{
[CompilerGenerated]
private IEnumerable<Gizmo> FabricatedMethod9()
{
return base.GetGizmos();
}

public override IEnumerable<Gizmo> GetGizmos()
{
Command_Action command_Action = new Command_Action
{
action = delegate
{
this.ToggleStateOne();
},
defaultDesc = Translator.Translate("MD2.MechWallRecessWallDesc"),
defaultLabel = Translator.Translate("MD2.MechWallRecessWallLable"),
activateSound = SoundDef.Named("Click"),
// hotKey = Keys.Named("RecessMechWall"),
disabled = false,
groupKey = 313740009,
icon = Building_MechWall.RecessIcon
};
yield return command_Action;
command_Action = new Command_Action
{
action = delegate
{
this.ToggleStateTwo();
},
defaultDesc = Translator.Translate("MD2.MechWallOpenEmbrasureDesc"),
defaultLabel = Translator.Translate("MD2.MechWallOpenEmbrasureLable"),
activateSound = SoundDef.Named("Click"),
// hotKey = Keys.Named("ExtendMechEmbrasure"),
disabled = false,
groupKey = 313740010,
icon = Building_MechWall.EmbrasureIcon
};
yield return command_Action;
if (this.FabricatedMethod9() != null)
{
using (IEnumerator<Gizmo> enumerator = this.FabricatedMethod9().GetEnumerator())
{
while (enumerator.MoveNext())
{
Command command = (Command)enumerator.Current;
yield return command;
}
}
}
yield break;
}

public override void ToggleStateOne()
{
if (base.HasPower)
{
// IntVec3 position = base.Position;
Thing thing = ThingMaker.MakeThing(Building_MechWall.MechWallRecessed, base.Stuff);
thing.SetFactionDirect(base.Faction);
thing.HitPoints = base.HitPoints;
Map map = base.Map;
this.Destroy(0);
this.DoDustPuff();
GenSpawn.Spawn(thing, Position, map, Rotation);
}
}

public override void ToggleStateTwo()
{
if (base.HasPower)
{
// IntVec3 position = base.Position;
Thing thing = ThingMaker.MakeThing(Building_MechWall.MechWallEmbrasure, base.Stuff);
thing.SetFactionDirect(base.Faction);
thing.HitPoints = base.HitPoints;
Map map = base.Map;
this.Destroy(0);
this.DoDustPuff();
GenSpawn.Spawn(thing, Position, map, Rotation);
}
}
}

public class Building_MechWallEmbrasure : Building_MechWall
{
private IEnumerable<Gizmo> FabricatedMethod9
{
get
{
return base.GetGizmos();
}
}

public override IEnumerable<Gizmo> GetGizmos()
{
new List<Gizmo>();
Command_Action command_Action = new Command_Action
{
action = delegate
{
this.ToggleStateOne();
},
defaultDesc = Translator.Translate("MD2.MechWallExtendWallDesc"),
defaultLabel = Translator.Translate("MD2.MechWallExtendWallLable"),
activateSound = SoundDef.Named("Click"),
// hotKey = Keys.Named("ExtendMechWall"),
disabled = false,
groupKey = 313740010,
icon = Building_MechWall.ExtendIcon
};
yield return command_Action;
command_Action = new Command_Action
{
action = delegate
{
this.ToggleStateTwo();
},
defaultDesc = Translator.Translate("MD2.MechWallRecessWallDesc"),
defaultLabel = Translator.Translate("MD2.MechWallRecessWallLable"),
activateSound = SoundDef.Named("Click"),
// hotKey = Keys.Named("RecessMechWall"),
disabled = false,
groupKey = 313740009,
icon = Building_MechWall.RecessIcon
};
yield return command_Action;
if (this.FabricatedMethod9 != null)
{
using (IEnumerator<Gizmo> enumerator = this.FabricatedMethod9.GetEnumerator())
{
while (enumerator.MoveNext())
{
Command command = (Command)enumerator.Current;
yield return command;
}
}
}
yield break;
}

public override void ToggleStateOne()
{
if (base.HasPower)
{
// IntVec3 position = this.Position;
Thing thing = ThingMaker.MakeThing(Building_MechWall.MechWallExtended, base.Stuff);
thing.SetFactionDirect(Faction.OfPlayer);
thing.HitPoints = base.HitPoints;
Map map = base.Map;
this.Destroy(0);
this.DoDustPuff();
GenSpawn.Spawn(thing, Position, map, Rotation);
}
}

public override void ToggleStateTwo()
{
if (base.HasPower)
{
// IntVec3 position = base.Position;
Thing thing = ThingMaker.MakeThing(Building_MechWall.MechWallRecessed, base.Stuff);
thing.SetFactionDirect(Faction.OfPlayer);
thing.HitPoints = base.HitPoints;
Map map = base.Map;
this.Destroy(0);
this.DoDustPuff();
GenSpawn.Spawn(thing, Position, map, Rotation);
}
}
}

[StaticConstructorOnStartup]
public abstract class Building_MechWall : Building
{
public static readonly Texture2D EmbrasureIcon = ContentFinder<Texture2D>.Get("UI/Icons/Metal", true);

public static readonly Texture2D ExtendIcon = ContentFinder<Texture2D>.Get("UI/Commands/DumpContentsUI", true);

public static readonly ThingDef MechWallEmbrasure = DefDatabase<ThingDef>.GetNamed("MD2MechEmbrasure", true);

public static readonly ThingDef MechWallExtended = DefDatabase<ThingDef>.GetNamed("MechWallExtended", true);

public static readonly ThingDef MechWallRecessed = DefDatabase<ThingDef>.GetNamed("MechWallRecessed", true);

public CompPowerTrader power;

public static readonly Texture2D RecessIcon = ContentFinder<Texture2D>.Get("UI/Commands/RecessWall", true);

private static readonly SoundDef sound = SoundDef.Named("ChunkRock_Drop");

public bool HasPower
{
get
{
return this.power != null && this.power.PowerOn;
}
}

public virtual void DoDustPuff()
{
MoteMaker.ThrowDustPuff(base.Position, Map, 1f);
SoundStarter.PlayOneShot(Building_MechWall.sound,new TargetInfo(base.Position, base.Map, false));
}

public override void SpawnSetup(Map map, bool respawningAfterLoad)
{
base.SpawnSetup(map, respawningAfterLoad);
this.power = base.GetComp<CompPowerTrader>();
}

public abstract void ToggleStateOne();

public abstract void ToggleStateTwo();
}
}


[attachment deleted by admin: too old]

BrokenValkyrie

#1
This is the code responsible for outputting the error.

    public TargetInfo(IntVec3 cell, Map map, bool allowNullMap = false)
    {
      if (!allowNullMap && cell.IsValid && map == null)
        Log.Warning("Constructed TargetInfo with cell=" + (object) cell + " and a null map.");
      this.thingInt = (Thing) null;
      this.cellInt = cell;
      this.mapInt = map;
    }


Check if the passed in map value is null.
Try using this.Map instead of base.Map .
I am curious if this is acceptable replacement code for the one that appears after this.DoDustPuff(); . Its a common format for other building type inheriting Building.

GenSpawn.Spawn(thing, Position, this.Map, Rotation);

Sorry If I couldn't be more of a help, I have to go now.

*edit
Well scratch my suggestion, none of it work.

BrokenValkyrie

I wrongly assumed it was the GenSpawn code that was causing the error. The actual error is caused by destroying the object.

this.Destroy(0);


Replace every instant of this.Destroy(0); with

this.DestroyedOrNull();

sulusdacor

thx a lot.
i did not even think to look at destroy XD