ID:139209
 
Code:
mob/verb/Loops()
infiniteLoop()
proc/infiniteLoop()
sleep(20)
spawn() infiniteLoop()


Problem description:

This may or may not just get closed since I've already submitted this as a bug report, but eh. BYOND tends to not fix my bugs, or at least not fix them soon. But anyway, the issue is that I have a loop that I call this way that crashes without an error after about a day and a half, so I need a way of doing this that does not crash. The bug report is here if you want to see what the problem is.

Essentially, any infinite loop that I call from world/New() crashes eventually. I thought it was just fine to do while(1) and let it go forever, as long as you didn't want to execute any code after the while loop started. If I'm wrong about that, replying to this post will be easy, but otherwise I'm wondering if anyone has had problems with calling infinite loops from world/New.

I've used infinite loops in projects before, and they can be especially handy in games that are hosted for days or weeks at a time, but I've never had problems with them silently crashing like this. And it's not my loop; I originally had one loop that was doing two completely different things at different rates, and I split it into two loops to see if one half of it was crashing, but they both eventually crash if I do that, and not at the same time. Currently I've got it back to one loop, and it just all happens inside world/New() in a while(1) instead of spawning and calling another function, because I thought spawning was the issue, since spawning causes the issue described in my bug report, but the procedure eventually crashes anyway.

Making a hidden admin verb that started the infinite loop wouldn't fix this, would it? I wouldn't do that permanently, but since I'm assuming that BYOND bug is related to my loops crashing, if someone thinks that'd work I might try it. These loops take at least half a day to crash, though, so it's kinda hard to debug.
proc/MyLoop()
while(1)
// do stuff
sleep(20)

world/New()
..()
spawn(1) MyLoop()


The spawn() is important since MyLoop() never ends you'll want to execute it without it blocking the rest of the code. What you're doing is recursion, not really a loop.
In response to Nadrew
That's one of the things I've tried, and it eventually crashes. And if I spawn first, I get the issue in the profiler that I described in the bug report I linked to. I've tried all (simple) combinations I can think of using while(1), spawning, and recursion. It also doesn't give any error messages at all when it crashes, which is weird. I always spawn before having a proc call itself, and generally before a while(1), and both of these should have to give an error to exit the loop.

Currently I've got two loops running: One updates the variable of every mob in the world every two seconds, which I could do in Stat() I guess but wow overhead, and the other backs up the world every half hour. Both loops crash within about an hour of each other, even though one loops way more times than the other (The loops crash about 12-24 hours after being called by world/New). Also, if I make them one loop like it was originally, and have the status update run every two seconds 900 times in a for-loop before backing up the world and repeating the whole process, it crashes way faster. Like, within two hours of the world starting.
In response to Cowdude
I don't know if this will work, but try it:
proc/loop()
//do stuff here
sleep(10)
loop()
In response to Martys1103
Martys1103 wrote:
I don't know if this will work, but try it:
> proc/loop()
> //do stuff here
> sleep(10)
> loop()
>


That will most definitely crash your game pretty quickly.