Results 1 to 9 of 9

Thread: Access violation when closing application

  1. #1
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Access violation when closing application

    Hi,

    I've got a very strange issue. Where by when running my application under the debugger I get an access violation when everything is being cleared up.

    However, if i run it outside of the debugger, in either release or debug mode, it exits cleanly.

    When my app closes, the destructors for various objects are called. In one of my destructors I have this code, which signals to an external thread, to stop, and then waits for that thread to exit - I do this with an event loop, so as not to freeze the GUI

    Qt Code:
    1. // A ten second timeout, to wait for the hotswap thread to exit
    2. // If it takes longer than this, then we'll just kill it off.
    3. QEventLoop EventLoop;
    4. QTimer WatchdogTimer(this);
    5. WatchdogTimer.setSingleShot(true);
    6. connect(&WatchdogTimer, SIGNAL(timeout()), &EventLoop, SLOT(quit()));
    7. connect(this, SIGNAL(finished()),&EventLoop, SLOT(quit()));
    8. WatchdogTimer.start(10000); // 10s timeout
    9.  
    10. // Signal hostswap thread quit before entering event loop
    11. osSignalWaitObject(m_Terminate_hot_swap_thread);
    12.  
    13. EventLoop.exec();
    To copy to clipboard, switch view to plain text mode 

    As I said, when the code is run in the debugger, I get an access violation when stepping over 'EventLoop.exec();'

    untitled.JPG

    Has anyone come across this issue before?

    David

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Access violation when closing application

    Event loop in destructor! This is bad idea. You will never know what will happen in this event loop, maybe some slots for this object are called corrupting destructor data.
    Anyway if application is closing why you need this event loop? waitFor for the thread should be ok and more safe.

    Why it is crushing it is hard to tell without wide context of code.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Access violation when closing application

    On which line in your code do you get the access violation?


    P.S
    Its hard to say without knowing your full project, but the way you are doing things seems dangerous and rigid.
    Since it seems you have a complex cleaning up which requires waiting, I would put that functionality in an object responsible only for cleaning up (and that class in its own thread).
    (this way you keep good design principals - in this case mainly "Single Responsibility Principle")
    It will free you from such "acrobatics" as you are doing with the event loop.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access violation when closing application

    Hi,

    I've got a bit further on this issue. I've removed the eventloop, and just have my event signalling to stop my thread:

    Qt Code:
    1. osSignalWaitObject(m_pCard_Page_HS_Manager->m_Terminate_hot_swap_thread);
    To copy to clipboard, switch view to plain text mode 

    which is an os independent waitobject wrapper.

    It would seem that as soon as I exit the run() method for my class, I get the access violation. Does anything specific happen when you exit the run() method of a qthread class?

    regards,

    David

  5. #5
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access violation when closing application

    Does anyone have any further thoughts on this issue?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Access violation when closing application

    The information you supplied is just not enough to say if this is a design problem or not.
    But it seems to me its more likely an implementation error - which is really hard for someone not familiar with your code to locate.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access violation when closing application

    The error suggests you are trying to dereference a pointer that is null. Getting a debugger backtrace should help pinpoint the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access violation when closing application

    I tried getting a backtrace, but there is no stacktrace visible just after the failure occurs, which i find very strange. I am currnetly at a loss how to proceed with this issue.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access violation when closing application

    What do you mean there is no stacktrace visible? Visible where? Did you ask the debugger for the trace? What did it say?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 8th January 2014, 08:15
  2. Access violation -- qobject.cpp
    By willief in forum Newbie
    Replies: 9
    Last Post: 14th February 2011, 22:55
  3. Access Violation - Crashing Application
    By LIRiot in forum Qt Programming
    Replies: 9
    Last Post: 5th December 2010, 23:10
  4. Access Violation with VS2008
    By Takatschio in forum Qt Programming
    Replies: 3
    Last Post: 19th August 2010, 09:16
  5. QModelIndexList access reading violation
    By Daxos in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2010, 08:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.