Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

After running the program in Qt Creator for some time, the "Application Output" in Creator printed "CSProxy Refcount XXX", and the program quit. exited with code 3



  • Dear all,
    Sorry for my English, please help me. Can anybody tell me about the meaning of“CSProxy refcount XXX”?

    Here is my code:

                 void  CreateDataFile()
                 {
                   //create four file every ten minutes
    
                    QString interval = "$";
    
                    qWarning()<<"FileCreatebegin1:"<<QDateTime::currentDateTime();
                    QString data1;
                    //data1.reserve(20000000); //if I allocate memory for data1,there are some changes to the statements printed by Application Output.See below.
                    //1)
                    for(int j=0;j<X_DataForSave.size();j++)  //the data is from sensors,"DataForSave" is QStringList
                    {
                        data1.append(X_DataForSave.at(j));
                        data1.append(interval);
                        data1.append(Y_DataForSave.at(j));
                        data1.append(interval);
                        data1.append(Z_DataForSave.at(j));
                        data1.append(interval);
                    }
                    qWarning()<<"before qCompress QString1 size = "<<data1.size();
                    QByteArray ba1 = data1.toLatin1();
                    qWarning()<<"tolatin1:"<<QDateTime::currentDateTime();
                    //2)compress
                    QByteArray combuffer1 = qCompress(ba1,-1);//using zlib
                    //3)create file
                    QString FileName1
                    =  "1"+QDateTime::currentDateTime().toString("yyyyMMddhhmm")+".da";//data file
                    QString filename1 =DirName+"/"+FileName1;
                    QFile file1;
                    file1.setFileName(filename1);
                    if(file1.open(QIODevice::WriteOnly))
                    {
                        file1.write(combuffer1);
                    }
                    file1.close();
                    qWarning()<<"FileCreateFinish1:"<<QDateTime::currentDateTime();
    
                   
                   .........
                  There are three similar code snippets,It's just that the subscripts of each variable have changed,for example "data1" is changed to "data2", "FileCreateFinish1" is changed to "FileCreateFinish2".
                   
    
    
                 }
    

    And here is what the "Application Output" prints:

    ...................
    FileCreatebegin1: QDateTime(2021-07-1311:10:00.633 中国标准时间 Qt::LocalTime)
    before qCompress QString1 size = 15796903 //emmm,maybe too large,About 30 mbyte.
    tolatin1: QDateTime(2021-07-13 11:10:00.872 中国标准时间 Qt::LocalTime)
    compress1: QDateTime(2021-07-13 11:10:01.773 中国标准时间 Qt::LocalTime)
    FileCreateFinish1: QDateTime(2021-07-13 11:10:01.775 中国标准时间 Qt::LocalTime)
    FileCreatebegin2: QDateTime(2021-07-13 11:10:01.778 中国标准时间 Qt::LocalTime)
    //before qCompress QString2 size = 16452403 //if i dont't preallocate memory for data2,this sentence will not be printed
    CSProxy refcount 42
    11:10:05: G:/myprogram/build-myprogram-Qt_5_13_2_MinGW_32_bit_static-Debug/debug/myprogram.exe exited with code 3

    This problem doesn't happen often.The above function is triggered by a timer and is executed every 10 minutes.The problem can occur about two hours after the program runs.
    I suspect it's due to a lack of memory,but the computer still has plenty of memory ,and I restarted the computer for a short time .
    And I'm curious why Qt didn't report an error.The font of ""CSProxy refcount 42" is not red.



  • @karilito
    I don't know where the message CSProxy refcount 42 comes from. Maybe from within the zlib library called from qCompress. Createor won't show it in red as it's just a message from somewhere, not an error. Don't know what its significance is.

    You are running 32-bit. 30MB files/strings should be alright, unless you have larger ones. But I agree the fact that pre-allocation makes it work may be indicative. Your variables stay in scope during this function, I don't know just how many more byte arrays you have after the code you show. Reduce that, or factor into separate functions, to test.

    Run your application in the debugger. See what happens when it "crashes".

    Do you anywhere attempt to read the zlib-compressed file(s) you generate? Because your

    QString FileName1 =  "1"+QDateTime::currentDateTime().toString("yyyyMMddhhmm")+".da";//data file
    file1.open(QIODevice::ReadWrite)
    

    is flawed and is likely to leave "corrupt" compressed files which zlib will error on if you try to deflate. This ought to be addressed regardless of your other error.



  • @JonB
    Thanks for your help.
    I've fixed my code and I am testing it again.
    The compressed file is only writed once. And I changed the code “file1.open(QIODevice::ReadWrite)” to "file1.open(QIODevice::WriteOnly)".
    After the code I show,the computer still have about 15504.4 MB free memory.I think the memory is sufficient. Is there too much memory fragmentation to allocate a large QString or QByteAarray?
    I will debug my code carefully. Thansk again.



  • @karilito
    Good for the WriteOnly.

    As I said, you should now run your code under the debugger. When it "crashes" it should break at the point of the crash. Look at the stack trace window to see where it is crashing and where in your code it was called from.

    Another possibility is to test writing the uncompressed string to the file, and not calling qCompress() at all. That should tell you whether zlib is connected to the issue at all?


Log in to reply