Unity hangs up on code

Hello,
i have a curious issue with c#:

Unity hangs itself up on a certain line:

g.maplist.Add (mapnumber, this); // this causes unity to hang up

Now adding a map to a dictionary should not be that dangerous.
What would be the normal way to debug this?
I was not able to attach a debugger to unity sadly. I get an unrecognized error.

I doubt adding to a dictionary is the real reason it’s hanging. I suggest showing some more code. Chances are, if it’s hanging, it may be because you’re creating an infinite loop that it gets stuck in.

1 Like

Yes i understand what you mean. But there is no loop near this. To find the problem line i inserted a return statement in my mapcreator. Its below.

        public Dictionary<int,maps> maplist = new Dictionary<int,maps>();

the maplist creation.

        public void createmaps() {
            prprofile ("createmaps"+mapname);
            gohook ();
            mapnumber = g.maplist.Count ();
            pre (str(mapnumber));
            return;
            g.maplist.Add (mapnumber, this); // this causes a hang

with this game works.

        public void createmaps() {
            prprofile ("createmaps"+mapname);
            gohook ();
            mapnumber = g.maplist.Count ();
            pre (str(mapnumber));
            g.maplist.Add (mapnumber, this); // this causes a hang
            return;

With this game hangs up.

I think there is actually something with dictionary wrong. maybe i messed it up somehow but i deleted now all custom code that might have done this.
Also maybe if there is a loop i dont see how to find it without some kind of trace there are too many occurances of the dictionary in the file.
Is there any way to check where exactly it hangs?

How is createmaps called? When debugging code, you can insert break points and step through it.

Thankyou i found the loop with my logs in files where i print to file the steps my game goes.
It is indeed somewhere completely else but is triggered by the dictionary not being empty.

Good to hear you were able to find the bug.