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

Multithreading Discussion :

QThread et Exception (MinGW => crash & VC9 => First-chance)


Sujet :

Multithreading

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Juin 2003
    Messages
    223
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Juin 2003
    Messages : 223
    Par défaut QThread et Exception (MinGW => crash & VC9 => First-chance)
    Bonjour,

    alors voici mon problème

    Durant l'exécution du QThread::run() il arrive qu'un exception soit lancée par une librairie tierce (OpenCV).

    Avec MinGW (GCC 4.4) j'obtiens:


    Un segmentation fault apres avoir executer le catch de mon exception:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Thread [2] (Suspended: Signal 'SIGSEGV' received. Description: Segmentation fault.)	
    	13 read_encoded_value_with_base()  0x00403cf6	
    	12 parse_lsda_header()  0x00403e03	
    	11 __gxx_personality_sj0()  0x004041a2	
    	10 _Unwind_SjLj_RaiseException() ..\..\..\..\gcc-4.4.1\gcc\unwind.inc:113 0x00409080	
    	9 __cxa_throw()  0x00404d6a	
    	8 OtherThread::run()  0x00402c95	
    	7 ZN7QThread11setPriorityENS_8PriorityE()  0x6a1d68be	
    	6 msvcrt!_itow_s()  0x75e61287	
    	5 msvcrt!_endthreadex()  0x75e61328	
    	4 KERNEL32!AcquireSRWLockExclusive()  0x75dc1194	
    	3 ntdll!RtlInsertElementGenericTableAvl()  0x7795b3f5	
    	2 ntdll!RtlInsertElementGenericTableAvl()  0x7795b3c8	
    	1 <symbol is not available> 0x00000000

    Avec VisualStudio 2008 J'obtiens:


    First-chance exception at 0x75cd9617 in exTest.exe: Microsoft C++ exception: char at memory location 0x0646fa64.
    (Je ne suis pas sur que cela soit grave mais j'aimerais savoir pourquoi ce message est affiché)

    Application type:

    J'ai donc écris ce matin une application qui simule le comportement de mon programme et de comment attraper les exceptions dans un QThread, voici le code du QThread (le reste se trouve dans le fichiers joints)

    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
     
    #include "OtherThread.h"
    #include <qDebug>
    #include <cstdio>
    #include "Errors.h"
     
    #ifdef USE_OPENCV
    #include <cv.h>
    #endif
     
     
    int OtherThread::count=0;
     
    enum
    {
    	EXC_NONE=0,
    	EXC_CLASSIC,
    	EXC_STD,
    	EXC_CVINTERN,
    	EXC_CVEXTERN,
    };
     
     
    OtherThread::OtherThread(QObject *parent, QComboBox *eType_, QSpinBox *wait_, QCheckBox *checkBox_)
    :QThread(parent), life(true), cbEType(eType_), spWaitTime(wait_), cbStop(checkBox_)
    {
    	count++;
    	ID=count;
    }
     
     
    void OtherThread::stop()
    {
    	if(isRunning())
    	{
    		life=false;
    		wait();
    	}
    	else
    	{
    		throw "Can not stop a not running thread";
    	}
    }
     
     
    void OtherThread::run()
    {
    	MY_FUNCNAME("OtherThread::run()")
     
     
    	int waitTime=spWaitTime->value();
    	int eType=cbEType->currentIndex();
    	bool catchStop = cbStop->isChecked();
    	int count=1, countMax=100;
    	char msg[50];
    	sprintf(msg,"#%d: Generate an error",ID);
     
     
    	qDebug() << "#"<<ID<<": Start => " << waitTime << " (ms), " << eType;
     
     
    	while(life)
    	{
    		qDebug() << "#"<<ID<<" => "<< count%countMax <<"  ("<<count<<")";
     
     
    		try
    		{
    			if(count%countMax==0)
    			{
    				if(eType==EXC_NONE)
    				{
    					qDebug() << "No exception thrown";
    				}
    				else if(eType==EXC_CLASSIC)
    				{
    					throw "classic exception";
    				}
    				else if(eType==EXC_STD)
    				{
    					std::vector<int> tab( 10 );
    					tab.at( 10 );	//Access to 11th elements
    				}
    				else if(eType==EXC_CVINTERN)
    				{
    					MY_ERROR(msg);
    				}
    				else if(eType==EXC_CVEXTERN)
    				{
    #ifdef USE_OPENCV
    					IplImage *src=cvCreateImage(cvSize(200,200),IPL_DEPTH_8U,3);
    					src->imageData=0;
    					cvSet(src,cvScalarAll(0));
    #else
    					throw "OpenCV extern is not defined";
    #endif
    				}
    				else
    				{
    					throw -1;
    				}
    			}
    		}
    		catch(const std::exception& e)
    		{
    			fprintf(stderr,"#%d: %s\n",ID,e.what());
    			fflush(stderr);
    			if(catchStop) stop();
    		}
    		catch(char * str)
    		{
    			fprintf(stderr,"#%d: %s\n",ID,str);
    			fflush(stderr);
    			if(catchStop) stop();
    		}
    		catch(...)
    		{
    			fprintf(stderr,"#%d: Unknown Error\n", ID);
    			fflush(stderr);
    			if(catchStop) stop();
    		}
     
    		msleep(waitTime);
    		count++;
    	}
     
    	qDebug() << "#"<<ID<<": Stop!!!!!!!!";
    }
    J'ai mis le projet entier avec le reste du code dans le fichier zip ci-joint.
    J'utilise CMake afin de générer le projet. OpenCV n'est lui pas nécessaire, mais peu etre inclus dans la compilation.

    Merci d'avance!
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. web service :A first chance exception..
    Par yan dans le forum Windows Mobile
    Réponses: 1
    Dernier message: 05/06/2009, 22h58
  2. Réponses: 2
    Dernier message: 27/06/2008, 16h03
  3. First Chance Exception
    Par Moustico dans le forum C#
    Réponses: 2
    Dernier message: 10/12/2007, 16h00
  4. Réponses: 18
    Dernier message: 09/10/2007, 10h20
  5. Réponses: 8
    Dernier message: 16/06/2005, 13h58

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