Random segfault



  • Hi, Does someone know what could possibly cause that segmentation fault? This happens after leaving a slot.

    //your coProcess terminating with default action of signal 11 (SIGSEGV): dumping core
    ==9495== Access not within mapped region
    at address 0x67
    ==9495== at 0x65E04A0: QCoreApplication::notifyInternal2(QObject
    , QEdoisvent*) (in /usr/lib/libQt5Core.so.5.6.0)
    ==9495== by 0x6634B8D: QTimerInfoList::activateTimers() (in /usr/lib/libQt5Core.so.5.6.0)
    ==9495== by 0x66350B0: ??? (in /usr/lib/libQt5Core.so.5.6.0)
    ==9495== by 0x80B4F06: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.4800.0)
    ==9495== by 0x80B515F: ??? (in /usr/lib/libglib-2.0.so.0.4800.0)
    ==9495== by 0x80B520B: g_main_context_iteration (in /usr/lib/libglib-2.0.so.0.4800.0)
    ==9495== by 0x6635C8E: QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) (in /usr/lib/libQt5Core.so.5.6.0)
    ==9495== by 0x65DE6F9: QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) (in /usr/lib/libQt5Core.so.5.6.0)
    ==9495== by 0x65E6B7B: QCoreApplication::exec() (in /usr/lib/libQt5Core.so.5.6.0)
    ==9495== by 0x41D745: MainApplication::MainApplication(int, char**) (in /home/tich/fixup/Group4/bin/qt)
    ==9495== by 0x418218: main (in /home/tich/fixup/Group4/bin/qt)


  • Qt Champions 2016

    @StoneTrooper

    Judging by the stack trace it happens in MainApplication::MainApplication, so then the question is, what's in MainApplication's constructor. One curiosity is why QCoreApplication::exec is called there in the first place ...
    Things to check are if the object that handles the slot hasn't been deleted by some means while the slot was executing. Without code it's hard to tell.



  • void MainApplication::goToProfile(unsigned int id =0){
    	_soundManager->playClickedSound();
    	delete _current;
    	_profile = new ProfileViewer(id,_width,_height,_main);
    	_current = _profile;
    	_soundManager->setMusic(_profile, QString("../Sound/cantina.wav"));
    	profileConnection();
    	emit raiseToolsSig();
    	_tools->hideMenus();
    }
    void MainApplication::menuConnection(){
    	connect(_menu,SIGNAL(profileSig(unsigned int)),this,SLOT(goToProfile(unsigned int)));
    	connect(_menu,SIGNAL(cardsSig()),this,SLOT(goToCards()));
    	connect(_menu,SIGNAL(deckSig()),this,SLOT(goToDeckMaker()));
    	connect(_tools,SIGNAL(sithOrJediSig()),_menu,SLOT(sithOrJediSlot()));
    	connect(_menu,SIGNAL(duelSig()),this,SLOT(goToDuel()));
    	connect(_menu,SIGNAL(rankingSig()),this,SLOT(goToRanking()));
    	connect(_menu,SIGNAL(successSig()),this,SLOT(goToSuccesses()));
    	connect(_menu,SIGNAL(hoveredSoundSig()),this,SLOT(hoveredSoundSlot()));
    }
    void MainApplication::profileConnection(){
      	connect(_profile,SIGNAL(quitApplication()),this,SLOT(quitApp()));
    	connect(_tools,SIGNAL(sithOrJediSig()),_profile,SLOT(sithOrJediSlot()));
      	connect(_profile,SIGNAL(goBackToMenuSig()),this,SLOT(goBackToMenuSlot()));
      	connect(_profile,SIGNAL(changeUserSig(unsigned int)),this,SLOT(goToProfile(unsigned int)));
      	connect(_profile,SIGNAL(profileToDeckSig()),this,SLOT(goToDeckMaker()));
      	connect(_profile,SIGNAL(profileToCardsSig()),this,SLOT(goToCards()));
      	connect(_profile,SIGNAL(psSig()),this,SLOT(goToSuccesses()));
    

    So basicly I have two signals linked with that slot one in menuConnection. This one is used to go from the menu to the profile. it never causes segfaults.The other one in profile Connection receives a signal from the profile and goes into the same slot to create an other player's profile. The execution goes to the end of that slot then segfaults but not always.This is all in mainApplication.


  • Qt Champions 2016

    @StoneTrooper
    Yet, the question remains: What do you have in your constructor and how do you set up your application and other QObjects?



  • Here's MainApplication

    
    ```MainApplication::MainApplication(int argc , char** argv) : QApplication(argc,argv)  {
    	_main = new QMainWindow();
    	_main->setStyleSheet("background : transparent");
    	QRect rec(desktop()->screenGeometry());
    	_width = rec.width();
    	_height = rec.height();
    	_tools = new ToolWidgets(_width,_height,_main);
    	_login = new LoginWindow(_width,_height,_main);
    	_soundManager = new SoundManager(0.50);
    	_soundManager->setMusic(_login, QString("../Sound/Star_Wars.wav"));
    	toolWidgetsConnection();
    	loginConnection();
    	emit raiseToolsSig();
    	_tools->hideMenus();
    	_main->resize(_width,_height);
    	_main->show();
    	exec();
    }
    void MainApplication::loginConnection(){
    	connect(_login,SIGNAL(loginSig()),this,SLOT(goToMenuFromLogin()));
    	connect(_login,SIGNAL(clickedSoundSig()),this,SLOT(clickedSoundSlot()));
    	connect(_login,SIGNAL(hoveredSoundSig()),this,SLOT(hoveredSoundSlot()));
    	connect(_tools,SIGNAL(sithOrJediSig()),_login,SLOT(sithOrJediSlot()));
    }
    
    
    void MainApplication::clickedSoundSlot(){
    	_soundManager->playClickedSound();
    }
    
    void MainApplication::hoveredSoundSlot(){
    	_soundManager->playHoveredSound();
    }
    
    void MainApplication::makeDeckConnection(){
    	connect(_deck,SIGNAL(returnToMenuSignal()),this,SLOT(goBackToMenuSlot()));
    }
    
    
    void MainApplication::menuConnection(){
    	connect(_menu,SIGNAL(profileSig(unsigned int)),this,SLOT(goToProfile(unsigned int)));
    	connect(_menu,SIGNAL(cardsSig()),this,SLOT(goToCards()));
    	connect(_menu,SIGNAL(deckSig()),this,SLOT(goToDeckMaker()));
    	connect(_tools,SIGNAL(sithOrJediSig()),_menu,SLOT(sithOrJediSlot()));
    	connect(_menu,SIGNAL(duelSig()),this,SLOT(goToDuel()));
    	connect(_menu,SIGNAL(rankingSig()),this,SLOT(goToRanking()));
    	connect(_menu,SIGNAL(successSig()),this,SLOT(goToSuccesses()));
    	connect(_menu,SIGNAL(hoveredSoundSig()),this,SLOT(hoveredSoundSlot()));
    }
    void MainApplication::cardsConnection(){
    	connect(_cards,SIGNAL(quitApplication()),this,SLOT(quitApp()));
    	connect(_cards,SIGNAL(goBackToMenuSig()),this,SLOT(goBackToMenuSlot()));
    	connect(_tools,SIGNAL(sithOrJediSig()),_cards,SLOT(sithOrJediSlot()));
    }
    
    void MainApplication::decksConnection(){
    	connect(_deck,SIGNAL(quitApplication()),this,SLOT(quitApp()));
    }
    
    void MainApplication::profileConnection(){
      	connect(_profile,SIGNAL(quitApplication()),this,SLOT(quitApp()));
    	connect(_tools,SIGNAL(sithOrJediSig()),_profile,SLOT(sithOrJediSlot()));
      	connect(_profile,SIGNAL(goBackToMenuSig()),this,SLOT(goBackToMenuSlot()));
      	connect(_profile,SIGNAL(changeUserSig(unsigned int)),this,SLOT(goToProfile(unsigned int)));
      	connect(_profile,SIGNAL(profileToDeckSig()),this,SLOT(goToDeckMaker()));
      	connect(_profile,SIGNAL(profileToCardsSig()),this,SLOT(goToCards()));
      	connect(_profile,SIGNAL(psSig()),this,SLOT(goToSuccesses()));
    }
    
    void MainApplication::successConnection() {
    	connect(_success,SIGNAL(goBackToMenuSig()),this,SLOT(goBackToMenuSlot()));
    	connect(_tools,SIGNAL(sithOrJediSig()),_success,SLOT(sithOrJediSlot()));
    }
    
    void MainApplication::rankingConnection(){
    	connect(_tools,SIGNAL(sithOrJediSig()),_ranking,SLOT(sithOrJediSlot()));
    	connect(_ranking,SIGNAL(goBackToMenuSig()),this,SLOT(goBackToMenuSlot()));
    }
    
    void MainApplication::loadingConnection() {
    	connect(_loadingWindow, SIGNAL(initDuelComSig(unsigned)), this, SLOT(initDuelCom(unsigned)));
    }
    
    
    void MainApplication::initDuelCom(unsigned deckId) {
    	std::cout << "init duelcom" << std::endl;
    	_interfaceDuel = new DuelInterface();
    	_duelCom = new DuelComGUI(deckId, _loadingWindow->getUser(), _interfaceDuel);
    	pthread_mutex_lock(_duelCom->getLock());
    	connect(_duelCom, SIGNAL(initDuelWindowSig(bool)), this, SLOT(goToDuelFromLoading(bool)));
    	connect(_duelCom, SIGNAL(goBackToMenuSig()), this, SLOT(goBackToMenuSlot()));
    	connect(_duelCom, SIGNAL(goBackToMenuSig()), this, SLOT(deleteDuel()));
    	std::cout << "init duelcom done" << std::endl;
    }
    
    void MainApplication::deleteDuel() {
    	delete _interfaceDuel;
    	delete _duelCom;
    }
    
    void MainApplication::goToMenuFromLogin(){
    	_soundManager->playClickedSound();
    	delete _login;
    	_menu = new MenuScreen(_width,_height,_main);
    	_current = _menu;
    	menuConnection();
    	emit raiseToolsSig();
    	_tools->hideMenus();
    	_tools->initChatFriendsList();
    	_soundManager->setMusic(_menu, QString("../Sound/march_on_the_jedi_temple.wav"));
    }
    
    void MainApplication::goToProfile(unsigned int id =0){
    	_soundManager->playClickedSound();
    	delete _current;
    	_profile = new ProfileViewer(id,_width,_height,_main);
    	_current = _profile;
    	_soundManager->setMusic(_profile, QString("../Sound/cantina.wav"));
    	profileConnection();
    	emit raiseToolsSig();
    	_tools->hideMenus();
    }
    
    void MainApplication::goToCards(){
    	_soundManager->playClickedSound();
    	delete _current;
    	_cards = new CardsViewer(_width,_height,_main);
    	_current=_cards;
    	_soundManager->setMusic(_cards, QString("../Sound/cantina.wav"));
    	cardsConnection();
    	emit raiseToolsSig();
    	_tools->hideMenus();
    }
    
    void MainApplication::goToDeckMaker(){
    	_soundManager->playClickedSound();
    	delete _current;
    	std::cout<<"hellow"<<std::endl;
    	_deck = new DeckEditor(_width,_height,_main);
    	_soundManager->setMusic(_deck, QString("../Sound/cantina.wav"));
    	std::cout<<"coic"<<std::endl;
    	_current = _deck;
    	makeDeckConnection();
    	decksConnection();
    	std::cout<<"gefe"<<std::endl;
    	emit raiseToolsSig();
    	_tools->hideMenus();
    	std::cout<<"gffzzz"<<std::endl;
    }
    
    void MainApplication::goToDuel(){
    	_soundManager->playClickedSound();
    	delete _current;
    	_loadingWindow = new LoadingWindow(_width, _height, _main);
    	loadingConnection();
    	emit raiseToolsSig();
    	_tools->hideMenus();
    }
    
    void MainApplication::goToDuelFromLoading(bool isMyTurn) {
    	std::cout << "here" << std::endl;
    	delete _loadingWindow;
    	_duelWindow = new DuelWindow(isMyTurn, _width, _height, _duelCom->getInterface(), _main);
    	_current = _duelWindow;
    	_soundManager->setMusic(_duelWindow, QString("../Sound/Duel_of_the_fates.wav"));
    	_duelCom->initDuelWindow(_duelWindow);
    	emit raiseToolsSig();
    	_tools->hideMenus();
    	pthread_mutex_unlock(_duelCom->getLock());
    }
    
    void MainApplication::goToRanking(){
    	_soundManager->playClickedSound();
    	delete _current;
    	std::cout<<"jacquadirepasse"<<std::endl;
    	_ranking = new RankingWindow(_width,_height,_main);
    	_soundManager->setMusic(_ranking, QString("../Sound/cantina.wav"));
    	_current = _ranking;
    	rankingConnection();
    	emit raiseToolsSig();
    	_tools->hideMenus();
    }
    
    void MainApplication::goToSuccesses(){
    	_soundManager->playClickedSound();
    	delete _current;
     	_success = new SuccessViewer(_width,_height,_main);
     	_soundManager->setMusic(_success, QString("../Sound/cantina.wav"));
     	successConnection();
     	_current = _success;
     	emit raiseToolsSig();
     	_tools->hideMenus();
    }
    
    
    void MainApplication::goBackToMenuSlot(){
    	std::cout << "Back to menu" <<std::endl;
    	_soundManager->playClickedSound();
    	std::cout << "Delete current" <<std::endl;
    	delete _current;
    	std::cout << "Delete current ok" <<std::endl;
    	_menu = new MenuScreen(_width,_height,_main);
    	_current = _menu;
    	_soundManager->playClickedSound();
    	_soundManager->setMusic(_menu, QString("../Sound/march_on_the_jedi_temple.wav"));
    	emit raiseToolsSig();
    	_tools->hideMenus();
    	menuConnection();
    }
    
    
    void MainApplication::goBackToLoginSlot(){
    	delete _current;
    	_login = new LoginWindow(_width,_height,_main);
    	_current = _login;
    	_soundManager->playClickedSound();
    	_soundManager->setMusic(_login, QString("../Sound/Star_Wars.wav"));
    	emit raiseToolsSig();
    	_tools->resetChat();
    	_tools->hideMenus();
    	loginConnection();
    }
    
    
    void MainApplication::toolWidgetsConnection(){
    	connect(this,SIGNAL(raiseToolsSig()),_tools,SLOT(raiseToolsSlot()));
    	connect(_tools,SIGNAL(quitApplication()),this,SLOT(quitApp()));
    	connect(_tools,SIGNAL(volumeSig(int)), this, SLOT(setVolumeSlot(int)));
    	connect(_tools,SIGNAL(volumeMusicSig(int)), this, SLOT(setVolumeMusicSlot(int)));
    	connect(_tools,SIGNAL(backToLoginSig()), this, SLOT(goBackToLoginSlot()));
    }
    
    
    void MainApplication::setVolumeSlot(int newVolume) {
    	float volume = float(newVolume)/100;
    	_soundManager->setSoundVolume(volume);
    }
    
    void MainApplication::setVolumeMusicSlot(int newVolume) {
    	float volume = float(newVolume)/100;
    	_soundManager->setMusicVolume(volume);
    }
    
    
    
    void MainApplication::quitApp(){
    	quit();
    }

  • Qt Champions 2016

    @StoneTrooper

    You shouldn't derive QApplication for the purposes you're doing it, but lets forget that for a moment.
    Move exec() out of the constructor and make a queued invocation that will initialize all those things you do in the constructor, and see how that fares. Something like this:

    MainApplication::MainApplication(int argc , char** argv)
        : QApplication(argc,argv), _main(new QMainWindow)
    {
        QMetaObject::invokeMethod(this, "initializeMyApp", Qt::QueuedConnection);
    }
    
    void MainApplication::initializeMyApp()
    {
        _main->setStyleSheet("background : transparent");
        QRect rec(desktop()->screenGeometry());
        _width = rec.width();
        _height = rec.height();
        _tools = new ToolWidgets(_width,_height,_main);
        _login = new LoginWindow(_width,_height,_main);
        _soundManager = new SoundManager(0.50);
        _soundManager->setMusic(_login, QString("../Sound/Star_Wars.wav"));
        toolWidgetsConnection();
        loginConnection();
        emit raiseToolsSig();
        _tools->hideMenus();
        _main->resize(_width,_height);
        _main->show();
    }
    

    where the declaration would look like this:

    class MainApplication : public QApplication
    {
        Q_OBJECT
        // ...
    
    private:
        Q_INVOKABLE void initializeMyApp();
    };
    

    and you use it as one'd usually use the application object:

    int main(int argc, char ** argv)
    {
        MainApplication app(argc, argv);
    
        return QApplication::exec();
    }


  • ==2399== Process terminating with default action of signal 11 (SIGSEGV): dumping core
    ==2399==  Access not within mapped region at address 0x696E616BA6
    ==2399==    at 0x65E04A0: QCoreApplication::notifyInternal2(QObject*, QEvent*) (in /usr/lib/libQt5Core.so.5.6.0)
    ==2399==    by 0x6634B8D: QTimerInfoList::activateTimers() (in /usr/lib/libQt5Core.so.5.6.0)
    ==2399==    by 0x66350B0: ??? (in /usr/lib/libQt5Core.so.5.6.0)
    ==2399==    by 0x80B4F06: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.4800.0)
    ==2399==    by 0x80B515F: ??? (in /usr/lib/libglib-2.0.so.0.4800.0)
    ==2399==    by 0x80B520B: g_main_context_iteration (in /usr/lib/libglib-2.0.so.0.4800.0)
    ==2399==    by 0x6635C8E: QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/libQt5Core.so.5.6.0)
    ==2399==    by 0x65DE6F9: QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/libQt5Core.so.5.6.0)
    ==2399==    by 0x65E6B7B: QCoreApplication::exec() (in /usr/lib/libQt5Core.so.5.6.0)
    ==2399==    by 0x416C32: main (in /home/tich/fixup/Group4/bin/qt)
    
    `
    I still have the same error

  • Qt Champions 2016

    @StoneTrooper
    QCoreApplication::notifyInternal2 is responsible for the event dispatching, however the stack trace doesn't give much to work with. You have a segmentation fault so the ordinary advice is applicable: check for null dereferencing, double deletions, dangling pointers etc. If you can identify the exact user code that triggers it seeing the code would be helpful.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.