为什么我在播放代码时遇到此C ++错误(在抛出'std :: bad_alloc'实例后调用终止)?

时间:2017-02-09 11:49:04

标签: c++ opencv std

我编写了下面粘贴的代码来执行一个启动monotrack并生成轨道的方法。

void KalmanTracker::TrackInitiation(AssignData *track_, vector<int> *CT_order_, Camera *cam) 
{
    vector<int> CT_order= *CT_order_;

    Functions f;
    double T,X_MAX,X_MIN,Y_MAX,Y_MIN;
    int numtracks = 0;
    for(int curr_p=0; curr_p<track_->num_DTBP; curr_p++) { //plot in the current frame

        if(track_->Data_TBP.at(curr_p).Free == false) {

            for(int ant_p=0; ant_p<track_->num_DANT; ant_p++) { //plot in the previous frame

                T = track_->Data_TBP.at(curr_p).Dato.t_obt - track_->Data_ANT.at(ant_p).Dato.t_obt;
                X_MAX = track_->Data_ANT.at(ant_p).Dato.Est_PosXY.at(Xx) + MAX_SPEED*T + 3.0*sqrt(2.0*RX);
                X_MIN = track_->Data_ANT.at(ant_p).Dato.Est_PosXY.at(Xx) - MAX_SPEED*T - 3.0*sqrt(2.0*RX);
                Y_MAX = track_->Data_ANT.at(ant_p).Dato.Est_PosXY.at(Yy) + MAX_SPEED*T + 3.0*sqrt(2.0*RY);
                Y_MIN = track_->Data_ANT.at(ant_p).Dato.Est_PosXY.at(Yy) - MAX_SPEED*T - 3.0*sqrt(2.0*RY);
                if((track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Xx) < X_MAX) && (track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Xx) > X_MIN) &&
                   (track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Yy) < Y_MAX) && (track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Yy) > Y_MIN)) {

                    if((track_->Data_TBP.at(curr_p).Dato.Area > 10) && (track_->Data_ANT.at(ant_p).Dato.Area > 10) &&
                       (track_->Data_TBP.at(curr_p).Dato.InBox == false) && (track_->Data_ANT.at(ant_p).Dato.InBox == false)) {
                        f.InitiateMonotrack(track_,track_->Data_ANT.at(ant_p).Dato,track_->Data_TBP.at(curr_p).Dato,&CT_order,numtracks); //Start the monotrack
                        numtracks++;
                        track_->Data_TBP.at(curr_p).Free = true;
                    }
                }
            }
        }
    }

    // Reordering and saving CT_order
    int num_non_discarded = 0;
    for(int i=0; i<track_->num_CT+numtracks; i++) {

        if (CT_order.at(i) != -1) {
            CT_order.at(num_non_discarded) = CT_order.at(i);
            num_non_discarded++;
        }
    }
    track_->num_CT = min(num_non_discarded,MAX_CT-1); 

    // Copy CT_order to the CT_order of the track
    for(int i=0; i<track_->num_CT; i++)
        track_->CT_order.at(i) = CT_order.at(i);

    // Releasing previous plots
    int num_ANT = 0;
    for(int i=0; i<track_->num_DANT; i++)
        track_->Data_ANT.at(i).Free = true;

    // Copy the current plot to previous plot
    for(int curr_p=0; curr_p<track_->num_DTBP; curr_p++) {

        if (track_->Data_TBP.at(curr_p).Free == false) {

            track_->Data_ANT.at(num_ANT).Dato.t_obt = track_->Data_TBP.at(curr_p).Dato.t_obt;
            track_->Data_ANT.at(num_ANT).Dato.Est_PosXY.resize(2);
            track_->Data_ANT.at(num_ANT).Dato.Est_PosXY.at(Xx) = track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Xx);
            track_->Data_ANT.at(num_ANT).Dato.Est_PosXY.at(Yy) = track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Yy);
            track_->Data_ANT.at(num_ANT).Dato.Area = track_->Data_TBP.at(curr_p).Dato.Area;
            track_->Data_ANT.at(num_ANT).Dato.InBox = track_->Data_TBP.at(curr_p).Dato.InBox;
            track_->Data_TBP.at(curr_p).Dato.image.copyTo(track_->Data_ANT.at(num_ANT).Dato.image);
            track_->Data_ANT.at(num_ANT).Free = false;
            num_ANT++;
        }
    }
    track_->num_DANT = min(num_ANT,MAX_DTBP-1);
    // Releasing current plots
    for(int curr_p=0; curr_p<track_->num_DTBP; curr_p++)
        track_->Data_TBP.at(curr_p).Free = true;

    track_->num_DTBP = 0;
    *CT_order_= CT_order;
}

当我执行.cpp文件时,我不断收到错误消息:

terminate called after throwing an instance of 'std::bad_alloc'
terminate called recursively
  what():  std::bad_alloc

我已经收集到这与内存不足或变量从main()函数中掉出来了,但我无法弄清楚如何在这种特定情况下解决问题。如果它是相关的,我正在使用Linux计算机,在eclipse中编程,使用C ++语言和opencv以及boost库,因为我的项目有两个线程。

[编辑]调试器告诉我: Can't find a source file at "/build/glibc-t3gR2i/glibc-2.23/signal/../sysdeps/unix/sysv/‌​linux/raise.c" Locate the file or edit the source lookup path to include its location. 未找到的源是raise.c中的__GI_raise()。 在那个错误之后,控制台告诉我:

[xcb] Unknown sequence number while processing reply 
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called 
[xcb] Aborting, sorry about that. dronesNuevo: ../../src/xcb_io.c:635: _XReply: Assertion `!xcb_xlib_threads_sequence_lost' failed.

但是其他时候调试器告诉我: Thread 3 received signal SIGSEGV, Segmentation fault. [Cambiando a Thread 0x7fffe1f69700 (LWP 17536)] 1574 ../sysdeps/x86_64/multiarch/memcpy-ssse3-back.S: No existe el archivo o el directorio. __memmove_ssse3_back () at ../sysdeps/x86_64/multiarch/memcpy-ssse3-back.S:1574

和: Can't find a source file at "/build/glibc-t3gR2i/glibc-2.23/string/../sysdeps/x86_64/mul‌​tiarch/memcpy-ssse3-‌​back.S" Locate the file or edit the source lookup path to include its location. 在memcpy-sse3-back.S找不到__memmove_ssse3_back()的来源。

我得到的回溯:

*** Error in `path': double free or corruption (!prev): 0x00007fffa007ecb0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7ffff5e577e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7ffff5e5fe0a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7ffff5e6398c]
path[0x40d3b6]
path[0x40cc26]
path[0x40bd78]
path[0x40b3a2]
path[0x409f3f]
path[0x40813b]
path[0x412bd7]
path[0x43df93]
path[0x44826b]
path[0x447f38]
path[0x447ac2]
/usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0(+0x115d5)[0x7ffff6a5b5d5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7ffff59b06ba]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7ffff5ee682d]

0 个答案:

没有答案