小编Ale*_*lex的帖子

System.StackOverflowException错误

我正在尝试创建一个2D洞穴生成系统.当我运行程序时,我尝试从自己的类创建新对象后得到"System.StackOverflowException"异常.

我的洞穴发生器的工作原理如下

我创建了一个包含不同类型单元格(如墙,水或空白空间)的ID(整数)的地图.

首先,我的所有"Map"类都会创建一个填充墙的地图,然后在地图的中心创建一个"Miner"对象.矿工挖掘地图并制作洞穴.问题是我想创造更多的矿工.所以,我挖掘地图的Miner创造了另一个矿工.但是,当我这样做时,我得到一个"System.StackOverflowException"异常.

如何在程序中跟踪StackOverflow的原因.这是我的矿工代码:

Miner.cs

public class Miner
{
    Random rand = new Random();

    public string state { get; set; }
    public int x { get; set; }
    public int y { get; set; }
    public Map map { get; set; }
    public int minersCount;

    public Miner(Map map, string state, int x, int y)
    {
        this.map = map;
        this.state = state;
        this.x = x;
        this.y = y;
        minersCount++;

        if (state == "Active")
        {
            StartDigging();
        } …
Run Code Online (Sandbox Code Playgroud)

c# stack-overflow exception system

1
推荐指数
1
解决办法
6261
查看次数

标签 统计

c# ×1

exception ×1

stack-overflow ×1

system ×1