-1

I am having weird problem using QT creator. I am using latest version of qt creator and Qvector function(i tried also std::vector and same problem) In for loop i am calling recursive functions, example:

void add(bool in){
    global_var.push_back(in) //Qvector<bool>, global varible
    return;
}
void start(int x,int y,int z){
    for(int i=0;i<z;i++){
        if(i<z){
           add(true);
           start(x,y,z);
           start(x,y,z);
           return;
        }

    }
        add(false) 

    }

And then app randomly crash at some point and only error i am getting is:

    Process:               FIRST_program [24565]
Path:                  /Users/USER/Downloads/*/FIRST_program.app/Contents/MacOS/FIRST_program
Identifier:            feri.FIRST_program
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        Qt Creator [23775]
Responsible:           FIRST_program [24565]
User ID:               501

Date/Time:             2018-12-12 21:24:41.838 +0100
OS Version:            Mac OS X 10.14.1 (18B75)
Report Version:        12
Bridge OS Version:     3.0 (14Y667)
Anonymous UUID:        F7D655B5-7798-C8EF-925D-0F2BF1B2ABD3

Sleep/Wake UUID:       6384DE06-A77B-4893-9D81-3BC040DA989F

Time Awake Since Boot: 52000 seconds
Time Since Wake:       11000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_PROTECTION_FAILURE at 0x00007ffee4a8bff8
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [24565]

VM Regions Near 0x7ffee4a8bff8:
    MALLOC_SMALL           00007f9884800000-00007f9885800000 [ 16.0M] rw-/rwx SM=PRV  
--> STACK GUARD            00007ffee128c000-00007ffee4a8c000 [ 56.0M] ---/rwx SM=NUL  stack guard for thread 0
    Stack                  00007ffee4a8c000-00007ffee528c000 [ 8192K] rw-/rwx SM=SHM  thread 0

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   macbook.FIRST_program               0x000000010a97d690 QBasicAtomicInteger<int>::load() const + 16 (qbasicatomic.h:103)
1   macbook.FIRST_program               0x000000010a97f155 QtPrivate::RefCount::isShared() const + 21 (qrefcount.h:101)
2   macbook.FIRST_program               0x000000010a980d38 QVector<bool>::isDetached() const + 24 (qvector.h:106)
3   macbook.FIRST_program               0x000000010a981920 QVector<bool>::append(bool const&) + 64 (qvector.h:679)
4   macbook.FIRST_program               0x000000010a97b64d QVector<bool>::push_back(bool const&) + 29 (qvector.h:260)
5   macbook.FIRST_program               0x000000010a97afc8 MainWindow::add(bool) + 40 (mainwindow.cpp:204)
6   macbook.FIRST_program               0x000000010a97ae22 MainWindow::start(int, int, int, int) + 242 (mainwindow.cpp:132)
7   macbook.FIRST_program               0x000000010a97ae9b MainWindow::start(int, int, int, int) + 363 (mainwindow.cpp:139)
8   macbook.FIRST_program               0x000000010a97ae9b MainWindow::start(int, int, int, int) + 363 (mainwindow.cpp:139)
9   macbook.FIRST_program               0x000000010a97ae9b MainWindow::start(int, int, int, int) + 363 (mainwindow.cpp:139)
10  macbook.FIRST_program               0x000000010a97ae9b MainWindow::start(int, int, int, int) + 363 (mainwindow.cpp:139)
11  macbook.FIRST_program               0x000000010a97ae9b MainWindow::start(int, int, int, int) + 363 (mainwindow.cpp:139)
12  macbook.FIRST_program               0x000000010a97ae9b MainWindow::start(int, int, int, int) + 363 (mainwindow.cpp:139)
13  macbook.FIRST_program               0x000000010a97ae9b MainWindow::start(int, int, int, int) + 363 (mainwindow.cpp:139)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • please provide a [mcve] – eyllanesc Dec 12 '18 at 21:45
  • Your start(x,y,z) will loop forever because of z is not changed in each call. The program stack will be overflowed and crashed. You should rework your recursive function. What is the problem you are trying to solve ? – tunglt Dec 12 '18 at 22:41

1 Answers1

0

I recommend you use append for add elements in a QVector, it's equal to pus_back, because QVector typically allocate more memory than necessary.

void add(bool in){
    global_var.append(in) //Qvector<bool>, global varible
    return;
}

And your start method, will loop ever. How to call start method? the value of z it's not changed in each call and if z=0, then for condition not working.

So, What is the problem you are really trying to solve ?

I. Munoz
  • 35
  • 5