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

Assertion failed: (((!(((((((to))->tt_)) & 0x0F)) == (0)) || to != &(L->l_G)->nilvalue)) && "invalid index"), function lua_copy, file lapi.c, line 260. #491

Closed
HactarCE opened this issue Nov 29, 2024 · 2 comments

Comments

@HactarCE
Copy link

HactarCE commented Nov 29, 2024

Steps to reproduce

use mlua::prelude::*;

fn main() {
    mlua_issue_491().unwrap();
}

fn mlua_issue_491() -> LuaResult<()> {
    let lua = Lua::new();

    let pair_of_tables = (lua.create_table()?, lua.create_table()?);
    lua.create_function(move |_lua, ()| {
        _ = &pair_of_tables;
        Ok(())
    })?;

    for i in 0..10000 {
        println!("{i}");
        lua.create_table()?;
    }

    Ok(())
}
  • mlua 0.10.1 with features lua54 and vendored
  • rustc 1.82.0 (f6e511eec 2024-10-15)
  • Apple M2 Max running macOS Sequoia 15.1.1

On my machine, this produces the following output deterministically when run in debug mode:

...
323
324
Assertion failed: (((!(((((((to))->tt_)) & 0x0F)) == (0)) || to != &(L->l_G)->nilvalue)) && "invalid index"), function lua_copy, file lapi.c, line 260.
fish: Job 1, 'cargo run' terminated by signal SIGABRT (Abort)

This bug also occurs with lua53, lua52, and lua51, although the last number printed varies (still well below 1000).

I'm unable to reproduce this in release mode.

I found this because it happens around 5% of the time that I launch Hyperspeedcube 2. In that case, the closure is capturing a (Lua, LuaTable) instead of (LuaTable, LuaTable).

@khvzak khvzak closed this as completed in 5fd96c7 Nov 30, 2024
@khvzak
Copy link
Member

khvzak commented Nov 30, 2024

thank you for the report and example how to reproduce!

@HactarCE
Copy link
Author

Thank you so much for the prompt fix! It makes me unreasonably happy to see the cursed reproduction as a regression test.

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

2 participants