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

Segmentation fault(core dumped) when I try to instantiate RGBCamera with the compiled libflightlib.a #200

Open
FFuChen opened this issue Jan 30, 2024 · 0 comments

Comments

@FFuChen
Copy link

FFuChen commented Jan 30, 2024

When I wanted to write a program that mimics camera. cpp in the flightros folder to read depth maps and visualize them using OpenCV, I found that the program would have a core dump. I used gdb backtrace and found that an exception was thrown in the constructor of RGBCamera, displaying as: program received signal SIGSEGV, Segmentation fault. Does this mean there is inappropriate pointer usage, but my program only deleted the ROS section in camera.cpp? Is there anything unreasonable in my code?

// flightlib
#include "flightlib/bridges/unity_bridge.hpp"
#include "flightlib/bridges/unity_message_types.hpp"
#include "flightlib/common/quad_state.hpp"
#include "flightlib/common/types.hpp"
#include "flightlib/objects/quadrotor.hpp"
#include "flightlib/sensors/rgb_camera.hpp"
#include "opencv2/opencv.hpp"
using namespace flightlib;

int main(int argc, char *argv[]) {

  // unity quadrotor
  std::shared_ptr<Quadrotor> quad_ptr = std::make_shared<Quadrotor>();
  // define quadsize scale (for unity visualization only)
  Vector<3> quad_size(0.5, 0.5, 0.5);
  quad_ptr->setSize(quad_size);
  QuadState quad_state;

  //
  std::shared_ptr<RGBCamera> rgb_camera = std::make_shared<RGBCamera>();

  // Flightmare(Unity3D)
  std::shared_ptr<UnityBridge> unity_bridge_ptr = UnityBridge::getInstance();
  SceneID scene_id{UnityScene::WAREHOUSE};
  bool unity_ready{false};

  // Flightmare
  Vector<3> B_r_BC(0.0, 0.0, 0.3);
  Matrix<3, 3> R_BC = Quaternion(1.0, 0.0, 0.0, 0.0).toRotationMatrix();
  std::cout << R_BC << std::endl;
  rgb_camera->setFOV(90);
  rgb_camera->setWidth(640);
  rgb_camera->setHeight(360);
  rgb_camera->setRelPose(B_r_BC, R_BC);
  rgb_camera->setPostProcesscing(
  std::vector<bool>{true, true, true});  // depth, segmentation, optical flow
  quad_ptr->addRGBCamera(rgb_camera);

  // initialization
  quad_state.setZero();
  quad_ptr->reset(quad_state);

  // connect unity
  unity_bridge_ptr->addQuadrotor(quad_ptr);
  unity_ready = unity_bridge_ptr->connectUnity(scene_id);

  FrameID frame_id = 0;
  while (unity_ready) {
    quad_state.x[QS::POSZ] += 0.1;

    quad_ptr->setState(quad_state);

    unity_bridge_ptr->getRender(frame_id);
    unity_bridge_ptr->handleOutput();

    cv::Mat img;

    rgb_camera->getDepthMap(img);

    frame_id += 1;
    cv::Mat depth_gray = cv::Mat::zeros(img.size(), CV_8UC1);
    cv::normalize(img, depth_gray, 0, 255, cv::NORM_MINMAX, CV_8UC1);

    cv::imshow("depth", depth_gray);
    cv::waitKey(1000);

  }

    cv::destroyAllWindows();

  return 0;
}

The debug information:
image

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

1 participant