IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Crash d'application lors de la destruction d'instance.


Sujet :

C++

  1. #1
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut Crash d'application lors de la destruction d'instance.
    Salut,

    J'ai un code qui utilise OpenCV pour une transformation d'image.

    Le code fonctionne sans problème lors d'un premier appel mais crash lors de la destruction de l'instance précédemment créée.

    Le code est compilé comme librairie dynamique.

    Le backtrace de gdb:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
     
    Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff692e57c in free () from /lib/x86_64-linux-gnu/libc.so.6
    (gdb) backtrace
    #0  0x00007ffff692e57c in free () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x00007fffeff2f7fd in cv::Mat::~Mat() () from /usr/lib/libopencv_core.so.2.3
    #2  0x00007fffe33f6e75 in ImgProcess::~ImgProcess (this=0x49e8d10, __in_chrg=<optimized out>) at imgprocess.cpp:192
    #3  0x00007fffe35fb2c9 in sipImgProcess::~sipImgProcess (this=0x49e8d10, __in_chrg=<optimized out>) at ./sipimgprocessImgProcess.cpp:41
    #4  0x00007ffff5b92fb4 in forgetObject (sw=0x140fa70) at /build/buildd/sip4-4.13.2/siplib/siplib.c:10124
    #5  0x00007ffff5b937d9 in sipWrapper_dealloc (self=0x140fa70) at /build/buildd/sip4-4.13.2/siplib/siplib.c:9675
    #6  0x000000000045c7b8 in subtype_dealloc.25367 ()
    #7  0x000000000054d375 in insertdict.18183 ()
    #8  0x00000000005209e9 in PyDict_SetItem ()
    #9  0x00000000004a22fb in _PyObject_GenericSetAttrWithDict ()
    #10 0x00000000004a25dd in PyObject_SetAttr ()
    #11 0x0000000000466e69 in PyEval_EvalFrameEx ()
    #12 0x0000000000466a42 in PyEval_EvalFrameEx ()
    #13 0x000000000057bd02 in PyEval_EvalCodeEx ()
    #14 0x000000000057dcd0 in function_call.15042 ()
    #15 0x00000000004bf2a6 in PyObject_Call ()
    #16 0x00000000004a4b8a in instancemethod_call.8548 ()
    #17 0x00000000004bf2a6 in PyObject_Call ()
    #18 0x00000000004bf5a6 in PyEval_CallObjectWithKeywords ()
    Python Exception <class 'gdb.error'> Il n'y a pas de membre nommé ob_ival.: 
    #19 0x00007ffff5b9df80 in sip_api_invoke_slot (slot=<optimized out>, sigargs=) at /build/buildd/sip4-4.13.2/siplib/qtlib.c:203
    #20 0x00007ffff58c3396 in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so
    #21 0x00007ffff58c3690 in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so
    #22 0x00007ffff58c3772 in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so
    #23 0x00007ffff5403489 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
    #24 0x00007ffff3adcc72 in QAbstractButton::clicked(bool) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #25 0x00007ffff381aa4e in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #26 0x00007ffff381bd8b in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #27 0x00007ffff381bffc in QAbstractButton::mouseReleaseEvent(QMouseEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #28 0x00007ffff43fb96f in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtGui.so
    #29 0x00007ffff349d144 in QWidget::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #30 0x00007ffff440303f in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtGui.so
    #31 0x00007ffff344c894 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #32 0x00007ffff34520bf in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #33 0x00007ffff4402a99 in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtGui.so
    #34 0x00007ffff53eee9c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
    #35 0x00007ffff344d862 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) ()
       from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #36 0x00007ffff34ccbf5 in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #37 0x00007ffff34cbbae in QApplication::x11ProcessEvent(_XEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #38 0x00007ffff34f50d2 in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #39 0x00007ffff4abed53 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
    #40 0x00007ffff4abf0a0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
    #41 0x00007ffff4abf164 in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
    #42 0x00007ffff541e3bf in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
    #43 0x00007ffff34f4d5e in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
    #44 0x00007ffff53edc82 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
    #45 0x00007ffff53eded7 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
    #46 0x00007ffff53f2f67 in QCoreApplication::exec() () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
    #47 0x00007ffff43cec5e in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtGui.so
    #48 0x0000000000466254 in PyEval_EvalFrameEx ()
    #49 0x000000000057bd02 in PyEval_EvalCodeEx ()
    #50 0x000000000057c77d in PyRun_FileExFlags ()
    #51 0x000000000057e4a1 in PyRun_SimpleFileExFlags ()
    #52 0x0000000000512cfd in Py_Main ()
    #53 0x00007ffff68cc76d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
    #54 0x000000000041ba51 in _start ()
    Le code lui-même:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
     
    #include "/usr/include/opencv2/highgui/highgui.hpp"
    #include "/usr/include/opencv2/imgproc/imgproc.hpp"
    #include <iostream>
    #include <stdio.h>
    #include <fstream>
    #include "imgprocess.h"
     
    using namespace std;
    using namespace cv;
     
    int ImgProcess::loadColorImage ( char* p )
    {
        src = imread( p, 1 ) ;
     
        if( !src.data )
        { 
            cout << "Image not loaded\n" ;
            return -1 ; 
        }
     
        isize = src.rows * src.cols ;
        cout << "Image loaded\n" ;
        return 0 ;
    }
     
    int ImgProcess::getColorHistogram( char* p )
    {
        int ret = computeColorHistogram() ;
     
        ofstream outf(p, ios::out) ;
        if (!outf)
        {
            cout << "Enable to create file:" << p ;
            return -1 ;
        }
     
        for (int i = 0 ; i < 256 ; i++)
        {
            double val = cvRound(r_hist.at<float>(i)) ;
            outf << val << " " ;
        }
        outf << ", ";
     
        for (int i = 0 ; i < 256 ; i++)
        {
            double val = cvRound(g_hist.at<float>(i)) ;
            outf << val << " " ;
        }
        outf << ", ";
     
        for (int i = 0 ; i < 256 ; i++)
        {
            double val = cvRound(b_hist.at<float>(i)) ;
            outf << val << " " ;
        }
     
        outf.close() ;
        return 0 ;
    }
     
    int ImgProcess::computeColorHistogram()
    {
        vector<Mat> bgr_planes;
        split( src, bgr_planes );
     
        int histSize = 256;
        float range[] = { 0, 256 };
        const float* histRange = { range };
     
        bool uniform = true; bool accumulate = false;
     
        calcHist( &bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );
        calcHist( &bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );
        calcHist( &bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );
     
        return 0 ;
    }
     
    int ImgProcess::applyContrastStretching( float lower, float upper, char* inf, char* outf )
    {
        cout << "applyContrastStretching\n" ;
        int ret = loadColorImage( inf );
        if (ret!=0)
        {
            cout << "Enable to read the file:" << inf ;
            return -1 ;
        }
     
        ret = computeColorHistogram() ;
     
        float c_hist [256] ;
     
        cout << "get chist blue\n";
        getCumulativeHistogram( b_hist );
        int bmin = getLowerTreshold( lower );
        int bmax = getUpperTreshold( upper );
     
        cout << "get chist green\n";
        getCumulativeHistogram( g_hist );
        int gmin = getLowerTreshold( lower );
        int gmax = getUpperTreshold( upper );
     
        cout << "get chist red\n";
        getCumulativeHistogram( r_hist );
        int rmin = getLowerTreshold( lower );
        int rmax = getUpperTreshold( upper );
     
        src.copyTo( target );
     
        setContrastStretching( bmin, bmax, 0 );
        setContrastStretching( gmin, gmax, 1 );
        setContrastStretching( rmin, rmax, 2 );
     
        imwrite( outf, target );
     
        cout << "Contrast stretching done\n";
     
        return 0;
     
    }   
     
    void ImgProcess::getCumulativeHistogram( Mat & hist )
    {
        c_hist[0] = hist.at<float>(0);
     
        for (int i = 1 ; i < 255 ; i++)
        {
            int j = i - 1;
            c_hist[i] = (c_hist[j] + hist.at<float>(i));
        }
    }
     
    int ImgProcess::getLowerTreshold( float factor )
    {
        int tmin = 0;
        int size = 255;
        while (tmin < size && c_hist[tmin] <= factor)
        {
            tmin += 1;
        }
     
        return tmin;
    }
     
    int ImgProcess::getUpperTreshold( float factor )
    {
        int tmax = 254;
        while (c_hist[tmax] > factor)
        {
            tmax -= 1;
        }
     
        return tmax + 1;
    }
     
    void ImgProcess::setContrastStretching(int min, int max, int index)
    {
        int norm [256];
        if (max <= min)
        {
            for( int y = 0 ; y < target.rows ; y++ )
            { 
                for( int x = 0 ; x < target.cols ; x++ )
                {
                    target.at<Vec3b>(y,x)[index] = 127;
                }
            }
        }
     
        else
        {
            int i;
            for (i = 0 ; i < min ; i++)
                norm[i] = 0;
     
            for (i = min ; i < max ; i++)
                norm[i] = (i - min) * 255 / ((max - min) + 0.5);
     
            for(i = max ; i < 255 + 1 ; i++)
                norm[i] = 255;
     
            for( int y = 0 ; y < target.rows ; y++ )
            { 
                for( int x = 0; x < target.cols; x++ )
                {
                    target.at<Vec3b>(y,x)[index] = norm[src.at<Vec3b>(y,x)[index]];
                }
            }
        }
    }
     
    ImgProcess::~ImgProcess()
    {
    }
    Seul l'appel de applyContrastStretching provoque le problème, les fonctions loadColorImage et getColorHistogram elles, peuvent être rappelées continûment.

    Le C++ est nouveau pour moi et j'ai supposé que c'est ma façon d'instancier les matrices qui est en cause.

    Merci de votre attention.

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Il manque la définition de la classe elle-même, et la plupart de tes chaînes devraient sans doute être déclarées const char*.

    PS: Pourquoi passer une valeur magique à imread() plutôt que la constante qui va bien?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  3. #3
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Si j'utilise char* p pour les chaînes (nom de fichier, en fait), c'est tout simplement parce que c'est ainsi dans le cours qui me sert de guide. Je regarde cela.

    Pour la définition de la classe, je pensais que cela ne devait se faire que dans le fichier d'entête, qui est comme ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    #include "/usr/include/opencv2/highgui/highgui.hpp"
    #include "/usr/include/opencv2/imgproc/imgproc.hpp"
     
    using namespace cv;
     
    /**
     * class ImgProcess
     */
    class ImgProcess
    {
    private :
        int computeColorHistogram () ;
        void getCumulativeHistogram ( Mat & ) ;
        int getLowerTreshold ( float factor ) ;
        int getUpperTreshold( float factor ) ;
        void setContrastStretching (int min, int max, int index) ;
        int ret ;
     
    public :
        Mat src ;
        Mat target ;
        int isize ;
        Mat b_hist ;
        Mat g_hist ;
        Mat r_hist ;
        float c_hist[] ;
        int loadColorImage ( char* ) ;
        int getColorHistogram ( char* ) ;
        int applyContrastStretching ( float, float, char*, char* ) ;
        virtual ~ImgProcess() ;
    } ;
    Si j'ajoute la définition de la classe dans le code, il faut aussi redéfinir les private et public ? à l'identique que dans le header ?

  4. #4
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Elle est bien là où elle doit être, c'est juste que tu ne l'avais pas postée, ce qui compliquait fort les choses, moussaillon!
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  5. #5
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Cette ligne est mauvaise:
    Elle place dans la classe un tableau de taille nulle, et tu écris dedans...

    Envoie-la par le fond.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

Discussions similaires

  1. Plantage lors de la destruction d'une classe
    Par xwindoo dans le forum C++
    Réponses: 10
    Dernier message: 04/10/2006, 16h01
  2. Réponses: 12
    Dernier message: 24/04/2006, 23h19
  3. Violation d'acces lors d'une destruction d'un composant
    Par Rayek dans le forum Composants VCL
    Réponses: 15
    Dernier message: 23/11/2005, 11h37
  4. Error in the application, lors du Rendu
    Par MatP dans le forum DirectX
    Réponses: 1
    Dernier message: 26/01/2005, 17h02
  5. Réponses: 2
    Dernier message: 17/08/2003, 20h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo