Azure-Kinect-Sensor-SDK icon indicating copy to clipboard operation
Azure-Kinect-Sensor-SDK copied to clipboard

cannot use k4arecord lib, fails to initialise due to spdlog exception at runtime

Open eidetic-av opened this issue 3 years ago • 3 comments

Describe the bug

Projects using k4arecord lib crash at runtime due to a spdlog exception claiming the k4a_logger is being initialised twice:

terminate called after throwing an instance of 'spdlog::spdlog_ex'
  what(): logger with name 'k4a_logger' already exists

In C++, the following simple code throws the above error:

#include <iostream>
#include <k4a/k4a.hpp>
#include <k4arecord/playback.hpp>

int main() {
  auto playback = k4a::playback::open("any-recording.mkv");

  k4a::capture capture;
  playback.get_next_capture(&capture);
  std::cout << "size: " << capture.get_color_image().get_size() << "\n";

  return 0;
}

Also, I have attempted to build and run the C example at examples/playback_external_sync which again fails with the same exception.

To Reproduce

  1. Install SDK
  2. Build either examples above
  3. Notice exception thrown at runtime

Expected behavior

No exception. Logger is initialised only once.

Logs

Screenshots

Desktop (please complete the following information):

  • OS: Both Arch Linux AND Windows 10 19043
  • SDK Version: 1.4.1, also tried compiling latest in develop branch

Additional context

eidetic-av avatar Sep 06 '22 01:09 eidetic-av

The k4a.lib and k4arecord.lib can't log to the same file. There is a note about this in the documentation: Azure Kinect Sensor SDK: Error and event logging (microsoft.github.io)

Confirm that your environment variables are using the same log file name for both libs.

dasparli avatar Sep 29 '22 18:09 dasparli

@dasparli thanks for this info. I'll try this again but set these environment variables. I wasn't aware of their existence.

Perhaps this info should be included in the readme here, since I presume the example won't actually run without first changing the vars.

eidetic-av avatar Oct 04 '22 01:10 eidetic-av

@dasparli Thank you for your tips, but I still have not solved the problem and would like to get your reply.

I had the same problem when I called k4a_transformation_create(&calibration).

The k4a.lib and k4arecord.lib can't log to the same file. There is a note about this in the documentation: Azure Kinect Sensor SDK: Error and event logging (microsoft.github.io)

I read the above file, but the log output to the file seems to be disabled by default.

I installed the SDK using vcpkg install azure-kinect-sensor-sdk and built the project using CMake. Here is a very short code that I can reproduce this error.

CMakeList.txt

cmake_minimum_required(VERSION 3.24)
project(k4aTest)

set(CMAKE_CXX_STANDARD 17)

find_package(k4a CONFIG REQUIRED)
find_package(k4arecord CONFIG REQUIRED)

add_executable(k4aTest main.cpp)

target_link_libraries(k4aTest PRIVATE k4a::k4arecord)
target_link_libraries(k4aTest PRIVATE k4a::k4a)

main.cpp

#include <k4a/k4atypes.h>
#include <k4a/k4a.h>
#include <k4arecord/playback.h>

#include <string>
std::string _video_path = "/path/to/master.mkv";

int main() {
    k4a_playback_t k4a_handle_;
    k4a_result_t result = k4a_playback_open(_video_path.c_str(), &k4a_handle_);
    if (result != K4A_RESULT_SUCCEEDED) {
        printf("fail\n");
        exit(-1);
    }
    k4a_calibration_t calibration;
    result = k4a_playback_get_calibration(k4a_handle_, &calibration);
    if (result != K4A_RESULT_SUCCEEDED) {
        printf("fail\n");
        exit(-2);
    }
    k4a_transformation_t k4a_point_cloud_transformation_handle_ = k4a_transformation_create(&calibration);
    if (k4a_point_cloud_transformation_handle_ == NULL) {
        printf("fail\n");
        exit(-3);
    }
    printf("finish");
    return 0;
}

The above code will give the same output as the current issue, both for Linux and Windows (with MinGW).

terminate called after throwing an instance of 'spdlog::spdlog_ex'
  what(): logger with name 'k4a_logger' already exists

Can you provide me with some ideas to solve this problem, is it a bug, or is there something wrong with my configuration.

yhf2000 avatar Mar 06 '23 10:03 yhf2000