简体   繁体   English

从不同的 cpp 调用回调函数会导致 bad_function_call

[英]Calling Callback function from different cpp causes bad_function_call

I'm currently working on an OpenCV project where I want to call a callback function in main.cpp from a different cpp.我目前正在处理一个 OpenCV 项目,我想从不同的 cpp 调用 main.cpp 中的回调函数。
The problem I'm facing is that when I want to call the function I get a bad_function_call because the Callback function is a null.我面临的问题是,当我想调用该函数时,我得到了一个 bad_function_call,因为 Callback 函数为空。

My main.cpp looks like this:我的 main.cpp 看起来像这样:

 PointDetection *detect;
 detect->houghCallback = [hPublisher] (std::vector<cv::Vec4i> data) {
        //do something
 };

my PointDetector.hpp, which gets included by the PointDetector.cpp:我的 PointDetector.hpp,它包含在 PointDetector.cpp 中:

 std::function <void (std::vector<cv::Vec4i> data) houghCallback;

My PointDetector.cpp, where I call the function looks like this:我在 PointDetector.cpp 中调用该函数的位置如下所示:

 void PointDetector::houghDetectCb(int status, void *userData) {
        std::vector<cv::Vec4i> houghPointsResult;
        PointDetector *self = static_cast<PointDetector *>(userData);    //This includes every variable in the hpp except the houghCallback for some reason 
        self->houghCallback(houghPointsResult);                          //This causes the bad_function_call because houghCallback is Null 
 }

Does somebody know if it is possible to call the Callback like this?有人知道是否可以像这样调用回调吗?

我找到了解决方案:我在实际的 GPU 操作之前调用了 stream.enqueqeHostCallback(参见这个问题: cuda 流:流执行后未调用回调

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导致std :: bad_function_call的原因是什么? - What causes std::bad_function_call? 使用Lambda的C ++回调失败并显示bad_function_call - C++ callback with lambda fails with bad_function_call stst :: bad_function_call的callstack - Callstack for std::bad_function_call 意外的std :: bad_function_call递归 - unexpected std::bad_function_call in recursion std :: bad_function_call自调用递归lambda但没有提示 - std::bad_function_call of self-calling recursive lambda but no hints std :: bad_function_call在visual studio中调用std :: swap时 - std::bad_function_call when calling std::swap in visual studio 从外部函数构造 std::function 给出 std::bad_function_call - Constructing std::function from extern functions gives std::bad_function_call c++ std::map 比较函数导致运行时“bad_function_call” - c++ std::map compare function leads to runtime "bad_function_call" 将 avx 变量传递给 std::function 时引发 bad_function_call 和分段错误 - bad_function_call thrown and segmentation fault caused when passing avx variables to std::function 为什么我的线程池有时会抛出 `std::bad_function_call` 或 `double free or corruption (!prev)` - Why does my thread pool sometimes throw `std::bad_function_call` or `double free or corruption (!prev)`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM