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

Saving not working correctly? #66

Open
DevLaTron opened this issue Sep 30, 2024 · 1 comment
Open

Saving not working correctly? #66

DevLaTron opened this issue Sep 30, 2024 · 1 comment

Comments

@DevLaTron
Copy link

I've built libresplit on an Ubuntu 24.04, and have had a couple of issues:

  • There seems to be a general error when saving, because json_dump_file returns 0 on success, so I rewrote this (Including debugging output) in src/timer.c

    result = json_dump_file(json, game->path, JSON_PRESERVE_ORDER | JSON_INDENT(2));
    if (result != 0) {
    printf("Error dumping JSON:\n%s\n", json_dumps(json, JSON_PRESERVE_ORDER | JSON_INDENT(2)));
    printf("Error: '%d'\n", result);
    printf("Path: %s\n", game->path);
    }
    json_decref(json);

    return result;

  • If the split times are "0", they won't be saved, which is probably your start point. Assuming that 0 means "not ran yet" (that's how it looks from the resources provided, I had to add checks for this to work correctly when updating the splits. It for example didn't do the memcpy initially, preventing saving.

  • I stumbled into all sorts of formatting issues between the game construct and the json. As a workaround I changed the serialize function to a simple long long to string conversion, and when loading the json use a strtoll() call to get it back. Of course at that point one could use an int to store that value.

After these adjustments, I finally managed to get it to run.

I'll leave this here for reference, as it's a "it's ugly, but it works for me" kind of hack.

If I find the time, I might clean this up and get it into correct working order with a PR.

@EXtremeExploit
Copy link
Collaborator

From what i read and the current code in that part is that you just added a printf telling the user what the error was when saving a json that failed, json_dump_file in the current code is inverted so the logic is really the same
This is how it is right now in master

if (!json_dump_file(json, game->path,
            JSON_PRESERVE_ORDER | JSON_INDENT(2))) {
        error = 1;
    }
json_decref(json);

I dont see any problem with adding a printf to the error code, feel free to PR when you feel like it

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