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

get_all_params error (std::future_error: Promise already satisfied) #1785

Closed
elbarto1980 opened this issue May 21, 2022 · 7 comments · Fixed by #1788
Closed

get_all_params error (std::future_error: Promise already satisfied) #1785

elbarto1980 opened this issue May 21, 2022 · 7 comments · Fixed by #1788
Labels

Comments

@elbarto1980
Copy link
Contributor

elbarto1980 commented May 21, 2022

Hi, I am running MAVSDK 1.4.0 on Ubuntu 20.04.
I am trying to get all PX4 params using the get_all_params() function and I noticed that the prom.set_value(all_params); line of code causes a segmentation fault. It happens every time, if the program does not terminate immediately after receiving the parameters list.
The error I get is:

terminate called after throwing an instance of 'std::future_error'
what(): std::future_error: Promise already satisfied

I think this issue might be somehow related to another issue ( #1527) that @julianoes fixed on September 2021.

Hopefully, these few following lines of code should be useful to reproduce the error:

#include <mavsdk/mavsdk.h>
#include <mavsdk/plugins/param/param.h>
#include <thread>
#include <iostream>

using namespace mavsdk;

int main() {
    Mavsdk mavsdk;

    mavsdk.add_udp_connection();
    std::this_thread::sleep_for(std::chrono::seconds(2));

    auto system = mavsdk.systems().at(0);
    auto param = Param{system};
    auto all_params = param.get_all_params();

    for (auto param : all_params.int_params) {
        std::cout << param.name << std::endl;
    }

    int i = 60;
    do {
        std::this_thread::sleep_for(std::chrono::seconds(1));
        i--;
        std::cout << i << std::endl;
    } while (i>0);
}

Thank you!

@julianoes
Copy link
Collaborator

julianoes commented May 22, 2022

Thanks for the issue @elbarto1980, and sorry that I broke that during the recent refactoring it's broken. I will look into it.

@elbarto1980
Copy link
Contributor Author

elbarto1980 commented May 23, 2022

Thank you @julianoes for providing a fix so quickly!
Could you please leave this issue open just for a couple more days? My code (the actual code, not the example above) is still crashing at the same point with the same error and I would like to investigate the error more thoroughly. Thanks

A few hours later.....

Sorry for the multiple edits but I think I found what makes my code crash... I send a set_takeoff_altitude() command after the get_all_params() command, and it makes it crash as it crashed before.

The following example should reproduce what happens:

#include <mavsdk/mavsdk.h>
#include <mavsdk/plugins/action/action.h>
#include <mavsdk/plugins/param/param.h>
#include <thread>
#include <iostream>

using namespace mavsdk;

int main() {
    Mavsdk mavsdk;

    mavsdk.add_udp_connection();
    std::this_thread::sleep_for(std::chrono::seconds(2));

    auto system = mavsdk.systems().at(0);

    auto param = Param{system};
    auto all_params = param.get_all_params();

    for (auto param : all_params.int_params) {
        std::cout << param.name << std::endl;
    }

    std::this_thread::sleep_for(std::chrono::seconds(2));

    auto action = Action{system};
    auto setTakeoffAltitudeResult = action.set_takeoff_altitude(15.0f);
    if (setTakeoffAltitudeResult != Action::Result::Success) {
        std::cerr << "Set takeoff altitude failed: " << setTakeoffAltitudeResult << std::endl;
    } else {
        auto takeoffResult = action.takeoff();
        if (takeoffResult != Action::Result::Success) {
            std::cout << "Takeoff failed: " << takeoffResult << std::endl;
        }
    }

    int i = 60;
    do {
        std::this_thread::sleep_for(std::chrono::seconds(1));
        i--;
        std::cout << i << std::endl;
    } while (i>0);
}

Thank you

@julianoes
Copy link
Collaborator

Oh, a new twist on this? 🤔 Let's see.

@julianoes
Copy link
Collaborator

There was indeed another bug, thanks for the nice example to reproduce it.

See: 5ce3a5c

@julianoes
Copy link
Collaborator

Thanks again for your help @elbarto1980. The minimal examples to reproduce this were very helpful, and allowed me to quickly pinpoint what was wrong!

@julianoes julianoes added the bug label May 26, 2022
@elbarto1980
Copy link
Contributor Author

Glad to be of help! Thank you @julianoes for fixing it... it's working flawlessly now.

@julianoes
Copy link
Collaborator

Nice, yes I backported the fixes to v1.4.2, until v2.0.0 ships.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants