Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows/Android]: runtime bug, native.showAlert doest works in coroutine #686

Open
1 task done
Be1zebub opened this issue Mar 21, 2024 · 3 comments
Open
1 task done

Comments

@Be1zebub
Copy link

Be1zebub commented Mar 21, 2024

Describe the bug
native.showAlert called in coroutine, cant call a listener callback.
Seems like it happens with other functions, i found https://forums.solar2d.com/t/bug-in-native-showalert-callback/318051 which report the same issue with network.setStatusListener on MacOS.

To Reproduce
put in main.lua to minimal reproduce:

coroutine.wrap(function()
    native.showAlert("Title", "Desc", {"OK"}, print)
end)()

Target platform and where build was made:
On Android 13 (DokeOS 4.0, live build) - nothing happens, callback just not called

Windows 10 22H2, Simulator: runtime error, with no info.

20:40:17.032  ERROR: Runtime error
20:40:17.032  attempt to call a nil value

whole test project or build.settings
Just empty project, with main.lua, no build.settings

coroutine.wrap(function()
    native.showAlert("Title", "Desc", {"OK"}, print)
end)()
@Be1zebub
Copy link
Author

Be1zebub commented Mar 21, 2024

Workaround:

coroutine.wrap(function()
    timer.performWithDelay(0, function()
        native.showAlert("Title", "Desc", {"OK"}, print)
    end)
end)()

@ggcrunchy
Copy link
Contributor

ggcrunchy commented Mar 21, 2024

The relevant line is: https://github.com/coronalabs/corona/blob/master/librtt/Rtt_LuaLibNative.cpp#L107

That LuaResource( ... ) bit is trying to pull the function off the wrong stack, after it grabs the main Lua state. (I don't know what the motivation for doing that is, off-hand.)

Temporarily copying the function onto the main state's stack seems to work. Tested with this replacement code:

            LuaContext *ctx = LuaContext::GetContext( L );
            if ( ctx->L() != L )
            {
                lua_pushvalue( L, callbackIndex );
                lua_xmove( L, ctx->L(), 1 );
                
                callbackIndex = -1;
            }
            resource = Rtt_NEW( & platform.GetAllocator(), LuaResource( ctx->LuaState(), callbackIndex ) );
            if ( ctx->L() != L )
            {
                lua_pop( ctx->L(), 1 );
            }

This was tested on Mac.

@clang-clang-clang
Copy link
Contributor

I also encountered this problem, in coroutine can get normal parameters, string, number, etc., but can not get callback (on a different lua_State).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants