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

Safeguard for Ticker internal storage that may be changed during callback execution #8820

Merged
merged 4 commits into from
Jan 26, 2023

Commits on Jan 20, 2023

  1. Ticker callback should be allowed to be destroyed

    Mainly, we protect std::function and variant itself from undefined
    behaviour when the underlying object is destroyed and then re-created
    with something else inside of it.
    
    For example, every captured object would be destroyed.
    ```cpp
    Ticker ticker;
    void oops(Job job) {
        ticker.once(1.0f,
            [job = std::move(job)]() {
                ticker.once(job.next(), do_something_else);
                job.work(); // ~Job() just happened!
            });
    }
    ```
    
    Another important case is repeating through once()
    ```cpp
    Ticker ticker;
    void repeat() {
        ticker.once(1.0f, repeat);
        puts("tick");
    }
    
    void setup() {
        repeat();
    }
    ```
    
    Temporarily moving callback object into the function and returning
    earlier should solve both cases.
    mcspr committed Jan 20, 2023
    Configuration menu
    Copy the full SHA
    1623b6a View commit details
    Browse the repository at this point in the history
  2. words

    mcspr committed Jan 20, 2023
    Configuration menu
    Copy the full SHA
    1261b28 View commit details
    Browse the repository at this point in the history

Commits on Jan 26, 2023

  1. Configuration menu
    Copy the full SHA
    be582b2 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    3ca47a6 View commit details
    Browse the repository at this point in the history