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

Panic when mutating world from proxied raw method #115

Open
Joakker opened this issue Apr 19, 2024 · 4 comments
Open

Panic when mutating world from proxied raw method #115

Joakker opened this issue Apr 19, 2024 · 4 comments

Comments

@Joakker
Copy link
Contributor

Joakker commented Apr 19, 2024

As the title says, when altering the world from the world pointer you can get from the context argument in the raw method, it yields a panic

#[derive(Resource, Reflect, LuaProxy)
#[reflect(Resource, LuaProxy)]
#[
    derive(clone),
    functions[
        r#"
            #[lua(kind = "Method", raw)]
            fn update(&self, ctx: &Lua) -> Result<_, _> {
                let world = ctx.get_world();
                let world = world.write();

               // This is where it panics
                world.get_resource_mut::<SomethingElse>();
             }
        "#
    ]
]
struct MyProxy {
   cool_thing: String
}

I tried with the blocking and non blocking methods but to no avail

@makspll
Copy link
Owner

makspll commented Apr 20, 2024

Hi, what is the exact error message?

@Joakker
Copy link
Contributor Author

Joakker commented Apr 20, 2024

Concurrent read/write world access

@makspll
Copy link
Owner

makspll commented Apr 20, 2024

I think it may be that the macro blocks access to the world earlier in that generated function, this may be avoidable in raw functions as they do not necessarily need access to the world

@Joakker
Copy link
Contributor Author

Joakker commented Apr 20, 2024

That's precisely the problem. In my game there is a Controller component, which represents what faction a piece belongs to. I put a give_money() proxy method, so I need to reference and mutate the object that represents that faction

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