mbkarle / mind-the-fog

Roguelike JavaScript game--mind the fog!
2 stars 1 forks source link

Game Hangs On Refresh #132

Closed akarle closed 6 years ago

akarle commented 6 years ago

Sometimes the game hangs on refresh. To reproduce, simply hit refresh enough times...

Im thinking some sort of race condition in the loading of the files? Seems it didn't happen before the great divide (#115 )

akarle commented 6 years ago

Update:

By putting console.log's around start_game() I have determined that on the hang it never finishes start_game()

akarle commented 6 years ago

Happens in the build_floor() function. Confirmed 3 times

    room_list[0] = Floor0.build_floor();
    room_list[1] = Floor1.build_floor();
    room_list[2] = Floor2.build_floor();
    room_list[3] = Floor3.build_floor();
    room_list[4] = Floor4.build_floor();
    room_list[5] = Floor5.build_floor();
    room_list[6] = Floor6.build_floor();
    room_list[7] = Floor7.build_floor();
akarle commented 6 years ago

Update: Its actually in the init of either a fight room or a safe room...

room_list[this.floor_num][i] = new FightRoom("", type, this.tierList[Math.floor(Math.random()*this.tierList.length)], this.floor_num, maxLocs, this.npcRoom);
akarle commented 6 years ago

Found it!

It was in rollLocations, which, right in its comment, admits it is NOT suited for high num_locs and low space, as it adheres to the 8 rooks style of placing items (see here ).

We must have unknowingly scaled to the point where this could be an issue. Ill definitely look at it ASAP!

akarle commented 6 years ago

Fixed!

The brute force way of rolling locations works fine in big rooms, but could cause a hang NOT because we were trying to cram too many things in, NOR because it was taking too many passes to randomly generate an ok space BUT because of a bug in the verifying 8-rooks code!

The code was making sure each row and each column was a unique number, even in comparison to each other. (If something was in row 20, nothing could be in column 20). The correct way to do this is that they should be unique within rows/columns. The new implementation does this and is much cleaner.