Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Facing issue with coroutines

A topic by APurpleApple created Mar 27, 2023 Views: 141 Replies: 3
Viewing posts 1 to 4
(1 edit)

Hi, i've already sent you a mail about this a few weeks ago but it seems that you're more active around here

Calling functions on a state while a child thread state is running a coroutine seems to break it. My current workaround is to duplicate every operation i do to another state, which i then exclusively use to branch thread states out of. This is obviously not ideal, and poses all sort of other logistical issues.

Is this a limitation of the current version ? The in-dev one mentions coroutines as being wip, do you have a time estimate on the feature's release ?

The issue can be easily reproduced on a blank project using the following code :

state = lua_state_create()
lua_add_code(state, @"   function test(num)
       for i = 1, num do
             coroutine.yield(i)
        end
    end
    function disrupt()
    end
");
th = lua_thread_create(state);
if (lua_call_start(th, "test", 10)) {
    while (lua_call_next(th)) {
        show_debug_message("yield: " + string(lua_call_result));
        for (var i = 0; i < 5; i++)
        {
             lua_call(state, "disrupt")
         }
    }
    show_debug_message("result: " + string(lua_call_result));
}

Thanks for your time.

Developer

I have received your email but I have not been able to reproduce it in my test project with the code - either I accidentally fixed it since last release or this is a GameMaker bug that only exists in some runtimes.

No estimate for when the new version will be ready - there are some technical challenges (including coroutines, which work awfully weird in general) and also GM updates keep breaking my code - if you download the repository and compile it, the unit tests fail in good half of recent GM updates.

Well it definitely does not work on my side and on several other computer. If you don't mind, could you tell me what version of Gamemaker you are running ?
You can try to tweak the amount of iterations in each loops, it tends to change the outcome. Also most of the time it just fails silently and keeps running without finishing the loop.

Developer

Hm, yeah, I’m seeing that - in 2022.11.0.73 it seems to never (?) crash but calls it quits after 3 iterations. In 2023.2.1.90 it does 3 iterations most of the time. In 2023.1.1.81 it always (?) crashes. That’s pretty bad, I can’t think of why a choice of GM runtime would mess up Lua-side memory.