RimWorld

RimWorld

Giant crop
在生成地图完成后 进入游戏时有一条红字
这个是错误日志

Got ThingsListAt out of bounds: (180, 0, -2)
UnityEngine.StackTraceUtility:ExtractStackTrace ()
(wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.Log.Error_Patch2 (string)
Verse.Log:ErrorOnce (string,int)
Verse.ThingGrid:ThingsListAt (Verse.IntVec3)
Verse.GridsUtility:GetPlant (Verse.IntVec3,Verse.Map)
LingGiantCrop.Comp_GiantCrop:CompTickLong ()
Verse.ThingWithComps:TickLong ()
RimWorld.Plant:TickLong ()
Verse.Thing:DoTick ()
Verse.TickList:Tick ()
(wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.TickManager.DoSingleTick_Patch5 (Verse.TickManager)
Verse.TickManager:TickManagerUpdate ()
Verse.Game:UpdatePlay ()
Verse.Root_Play:Update ()


错误日志 Got ThingsListAt out of bounds: (180, 0, -2) 表明游戏尝试访问地图之外的非法坐标 (180, 0, -2)。具体原因如下:

坐标越界:

坐标 (180, 0, -2) 中的 Z = -2 是负数,而地图坐标通常从 (0,0,0) 开始。
地图边界范围通常是 (0,0,0) 到 (地图宽度-1, 0, 地图高度-1),负坐标或超出地图尺寸的坐标均非法。
问题触发点:

在 LingGiantCrop.Comp_GiantCrop.CompTickLong() 中调用 GridsUtility.GetPlant()。
GetPlant() 内部尝试通过无效坐标 (180,0,-2) 获取地图上的植物。
根本原因:

Mod LingGiantCrop(灵能巨作物) 在计算植物位置时未正确处理地图边界。
当巨型作物位于地图边缘时,其检测逻辑可能生成负坐标或超界坐标。
解决方案:
方法 1:修改 Mod 代码(推荐)
在 LingGiantCrop.Comp_GiantCrop.CompTickLong 中添加 边界检查:

Csharp
// 修改后的 CompTickLong 示例
public override void CompTickLong() {
base.CompTickLong();

Map map = this.parent.Map;
IntVec3 parentPosition = this.parent.Position;

// 示例:检查目标坐标是否合法
IntVec3 targetCell = new IntVec3(parentPosition.x + offsetX, 0, parentPosition.z + offsetZ);

// 关键修复:检查坐标是否在地图范围内
if (!targetCell.InBounds(map)) {
// 可选:记录一次错误(避免日志爆炸)
// Log.ErrorOnce($"LingGiantCrop: 坐标越界 {targetCell}", 123456);
return; // 直接退出避免崩溃
}

Plant plant = GridsUtility.GetPlant(targetCell, map);
// ...后续逻辑
}
关键修复点:
步骤 说明
1. 获取地图引用 通过 this.parent.Map 拿到当前地图对象。
2. 坐标边界检查 用 InBounds(map) 检查坐标有效性(RimWorld 内置方法)。
3. 提前退出 遇到非法坐标时跳过后续逻辑,防止游戏崩溃。
方法 2:临时应急措施
若无法修改代码,可在游戏中避免将 巨型作物 放置在地图边缘(至少留出 2 格缓冲距离)。

问题深层原因:
地图边缘计算缺陷: Mod 在计算周围植物坐标时,未考虑父物体位于地图边缘时 parent.Position + offset 可能越界。
TickLong 机制问题: CompTickLong 每 2000 tick 执行一次,当巨型作物被移动/移除后,残留的逻辑仍可能尝试访问旧坐标。
附加建议:
检查坐标计算逻辑: 确保所有类似 parent.Position + new IntVec3(x, 0, z) 的代码都包含边界检查。
验证地图引用: 在访问 parent.Map 前检查 parent 是否已被销毁:
Csharp
if (parent?.Map == null || parent.Destroyed) return;

这个是ds的分析 不知道能不能帮助你解决这个问题