Log In  


There used to be an issue where coroutines would yield unexpectedly if they took to long to execute.
This was fixed a while back, but I see that for coroutines that themselves run inside coroutines - this still happens.

In the below code, in the 'coroincoro' case, nil is yielded instead of 1, showing that the yield happened sometimes before the "real" yield call.

sleep=function() for i=0,100,0.00002 do end yield(1) end

function test(name, func, ...)
    local coro=cocreate(func, ...)
    local ok,result=coresume(coro)
    print(name..": "..tostr(ok)..", "..tostr(result))
end

test("coroutine", sleep)

local cc = cocreate(function()
    test("coroincoro", sleep)
end)
coresume(cc)
1


I inserted a flip() between the coroutines to isolate the second one vs. vblank, then twiddled the loop count until I found the sweet spot. It turns out the the works/doesn't work threshold is around 139K iterations or, in context, probably 8Mhz/60.

Definitely seems like a frame interrupt.


Nice catch, thanks @thisismypassword -- fixed for 0.2.4d

This was also happening when going over 2MB Lua RAM while inside a nested coroutine. It's supposed to exit the vm loop (luaV_execute), try a GC to see if it can stay under 2MB (usually the case), and then restore the thread stack when successful using the same process.



[Please log in to post a comment]