An awesome job, if I may say it. The idea of having a “safe break” for impossible rooms is clever. Something I need to add to my own code.
It could be good to add the option to delete the excess of terrain to save some memory and gain a few fps.Something like if “terrain object” not touching rooms nor hallways, delete them.
The place will look a bit emptier of course, yet you save some memory.
Checking some random numbers I made a dungeon that goes beyond the boundaries. You need to take in account the hallway’s size when making them. An adjust to the room creation limits or the hallway’s place so it doesn’t goes below 0 or over the terrain limit.
Maybe a condition in the creator like RandominRange(1+Hallways_size, (Terrain_size-Hallways_size)-1) so you get sure the rooms and hallways. I know it may not be as easy as it, but I hope it helps as an idea.