johanhelsing / bevy_pkv

Cross-platform (including wasm) persistent key value store plugin for rust games/apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bevy_pkv now completely broken

HyperAlch opened this issue · comments

If you run the "basic" example on native, it's completely bugged in different ways. In order to reproduce the first bug, delete any existing data written to the hard drive by bevy_pkv. In this I delete /home/.local/share/basicexample. This will give us a clean slate.

Now if you run cargo run --example basic this is what you get:

image

As you can see, there is zero output.
However, if you rerun the basic example a second time, you get this:

image

As you can see, the first run was able to write our Key-Value pairs, but was unable to read it. However, after the Key-Value pairs are written, we are able to access them on the second run.


It doesn't stop there. The second bug I noticed is once you run the example a 2nd time, you are no longer able to change the value of the Key-Value pairs. For example if I change the example setup function code to this:

fn setup(mut pkv: ResMut<PkvStore>) {
    // strings
    if let Ok(username) = pkv.get::<String>("username") {
        info!("Welcome back {username}");
    } else {
        pkv.set_string("username", "alice222")
            .expect("failed to store username");

        // alternatively, using the slightly less efficient generic api:
        pkv.set("username", &"alice222".to_string())
            .expect("failed to store username");
    }

    // serde types
    if let Ok(user) = pkv.get::<User>("user") {
        info!("Welcome back {}", user.name);
    } else {
        let user = User {
            name: "bob222".to_string(),
        };
        pkv.set("user", &user).expect("failed to store User struct");
    }
}

Then run the example a 3rd time I get this:

image

Notice how the values did not change. However, if I delete the /home/.local/share/basicexample again and rerun, I'm once again given no output:

image

But rerunning it again now gives me the correct values:

image


Summary

  • When starting with no pre-existing data folder, the basic example is able to write, but not read.
  • From the 2nd time you run the example and onward, you are able to read the Key-Value pairs, but you are NOT able to write new values.

I don't understand... That's the behavior i'd expect.

    if let Ok(username) = pkv.get::<String>("username") {
        info!("Welcome back {username}");
    } else {
        pkv.set_string("username", "alice222")
            .expect("failed to store username");

This will only attempt to write a value if an existing one could not be found. It's trying to demo one-time setup

Adding an invalid tag. I think the "bug" here is probably that the example is confusing, it should either have better inline documentation, or do something less confusing.

What did you expect to happen?

You are 100% correct, I was confused. I have a sleeping disorder and I had only slept 4 hours in the past 3 days when I wrote this. Now that I have gotten some sleep I reread the code and everything looks fine.

However, I do know why I was confused. You had said you use the examples as sudo tests for WASM. So my sleep deprived brain thought that the code would work the same or close to the same as the tests.

My sincerest apologies, I will refrain from making any type of GitHub issue when sleep deprived in the future. I hope I didn't waste too much of your time.

No worries, it happens to all of us

I do think it points out that the examples could use a bit more explanation though, will close this issue and open another one.