stella-cv / stella_vslam

This is a unofficial fork of OpenVSLAM (https://github.com/xdspacelab/openvslam)
https://stella-cv.rtfd.io/en/latest/
Other
875 stars 374 forks source link

Error when saving map using SQLite3 format #467

Closed MartiBolet closed 1 year ago

MartiBolet commented 1 year ago

Describe the bug

When saving a map with SQLite3 map format, it fails with following error:

[2023-02-07 16:27:00.636] [info] pause mapping module
[2023-02-07 16:27:00.641] [info] pause global optimization module
[2023-02-07 16:27:00.668] [error] SQLite error (prepare): not an error
[2023-02-07 16:27:00.668] [info] Failed save the map database
[2023-02-07 16:27:00.668] [info] resume global optimization module
[2023-02-07 16:27:00.668] [info] resume mapping module

To Reproduce

When trying to save a map after executing stella_vslam_ros.

build options:

  CMAKE_PREFIX_PATH=/opt/ros/${ROS_DISTRO}/lib/cmake cmake \
    -DUSE_PANGOLIN_VIEWER=OFF \
    -DUSE_SOCKET_PUBLISHER=ON \
    -DINSTALL_SOCKET_PUBLISHER=ON \
    -DUSE_STACK_TRACE_LOGGER=ON \
    .. 

Expected behavior

Saved the map completly

Screenshots or videos

Environment

Additional context

The map can save some tables, but the table that fails is keyframes and is empty. After searching for this error string I think the error is on the following function, where it will always return a nullptr because ret is hardcoded to SQLITE_ERROR:

sqlite3_stmt* create_insert_stmt(sqlite3* db,
                                 const std::string& name,
                                 const std::vector<std::pair<std::string, std::string>>& columns) {
    int ret = SQLITE_ERROR;
    sqlite3_stmt* stmt = nullptr;
    if (ret == SQLITE_OK) {
        std::string insert_stmt_str = "INSERT INTO " + name + "(id";
        for (const auto& column : columns) {
            insert_stmt_str += ", " + column.first;
        }
        insert_stmt_str += ") VALUES(?";
        for (size_t i = 0; i < columns.size(); ++i) {
            insert_stmt_str += ", ?";
        }
        insert_stmt_str += ")";
        ret = sqlite3_prepare_v2(db, insert_stmt_str.c_str(), -1, &stmt, nullptr);
    }
    if (!stmt) {
        spdlog::error("SQLite error (prepare): {}", sqlite3_errmsg(db));
    }
    return stmt;
}