ID:272893
 
So, I am working on a random map generator, and it was working perfectly fine. It can generate maps with no errors at all.

Until I introduce areas to the equation. First I tried to place them at the end of the map generation, I was given "BYOND BUG: Bad turf" errors, along with an error pointing to this section of the code.

            for(var/turf/T in block(locate(xx,yy,1),locate(xx+60,yy+60,1)))
if(V) new V(locate(T.x,T.y,1))


However, this problem is random at best. Sometimes it happens, sometimes it does not, it is a 50/50 chance really.

So I tried adding area generation to the start of the map generation process. It worked, but steps that came after, specifically those that generated turfs gave errors such as BYOND BUG: Bad Turf or Bad Loc, pointing to the code...

while(i)
new/turf/ground/Grass(locate(rand(250,550),rand(250,550),1))
i--


So I tried changing it to...


while(i)
T=locate(rand(250,550),rand(250,550),1)
if(T) new/turf/ground/Grass(locate(T.x,T.y,T.z))
i--


It resulted in no error message being given, but the proc does not finish executing, after which the entire map generation process stops (no reported CPU usage), the profiler reports no procs being run either. By using debug messages, it seems the proc stops running at the T=locate(rand(250,550),rand(250,550),1) line of code, and it is not an infinite loop either, as the debug messages after this line (or before) are not being output.
The best part is once this happens, things systematically start failing with BYOND. I cannot open the profiler, the map element stops working (verbs report I am moving around the map, and indeed interactions with the map report so too, but the map just does not change, whatever was on the map before it stopped working stays ecxactly as it was). Shortly after this, BYOND basically crashes.

If I manually place areas in the map editor, this exact same behaviour occurs.

If I remove areas from the process entirely, everything works fine. There is no errors, no problems, the map generator works exactly like it is intended too.

The only problem I can assume it is so far is that there is a lot of areas on the map (the map is 1000x1000, divided into 60x60 areas, but there is a border around the map with no areas, there is a total of 197 different areas on the map, including the border).

I thought maybe it'd be related to any procs the areas had and were possibly running. So I commented them out, and it had no effect at all.

So, anyone think they could explain this, and what is happening? Am I doing something wrong, or is it some sort of BYOND related bug?
How are you generating the /area's?

Also, locate(T.x,T.y,T.z) is redundant when T is a turf, as it will just return T.
In response to DarkCampainger
mob/proc/GenArea()
set background=1
var/xx
var/yy

var/v=1
var/area/V
var/xxx
var/yyy
for(xx=99,xx<=800,xx+=60)
for(yy=99,yy<=800,yy+=60)
V=AList[v]
world << "[V] [v]"
for(xxx=xx,xxx<=xx+60,xxx++)
for(yyy=yy,yyy<=yy+60,yyy++)

if(V) new V(locate(xxx,yyy,1))
v++
if(v>199) v=199

AList, which I have left out is just a list with all of the area types inside of it, all 196 of them.

I did originally use var/turf/T in block(), then generate areas in all of those turf locations, but the method above seems to have a higher success rate. But is still prone to just mysteriously not working.

Also, if I do not use locate(T.x,T.y,T.z), things generally tend to not work as intended.
What purpose do all of the areas serve? The way areas work is that there's only one instance of an area, but the area can be expanded by adding turfs to the area's contents.

I can create a new area then add all of the turfs onto the map into the area's contents and there's still only one instance of that area but it'll span the entire map. Here's a small example:

mob/verb/new_area()
var/area/A = new
var/turf/T1 = locate(1,2,3)
var/turf/T2 = locate(2,2,3)
A.contents.Add(T1,T2)
//The new area will now "cover" T1 and T2