Results 1 to 9 of 9

Thread: Program runs on Windows 7, crashes on Windows XP

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    55
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program runs on Windows 7, crashes on Windows XP

    The error is just a general Windows GPF, nothing very helpful.

    It crashes on XP, both 32- and 64-bit. It's fine on 7, both 32- and 64-bit.

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Program runs on Windows 7, crashes on Windows XP

    Perhaps you have a memory leak caused by some bad pointer wich randomly can point to some invalid memory position. Than it can crash or not. Try point your pointers to NULL when dealocating them, and check wath happens. Also try using some program like Valgrin to check memory leaks.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  3. #3
    Join Date
    Mar 2010
    Posts
    55
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program runs on Windows 7, crashes on Windows XP

    Ok, well I decided to install the dev environment on an extra laptop I have running Windows XP. Without any changes, I ran the program and perform just one conversion, the debugger stops me. Oddly enough, it stops me at ntdll!DbgUiConnectToDbg, with the signal "signal-received".

    I tried running the program through gdb, and sure enough, after one conversion it breaks with the following:

    Qt Code:
    1. Program received signal SIGTRAP, Trace/breakpoint trap.
    2. 0x7c90120f in ntdll!DbgUiConnectToDbg () from C:\WINDOWS\system32\ntdll.dll
    To copy to clipboard, switch view to plain text mode 

    Why is there a breakpoint in a system DLL?

    [update]
    Ok, well I think I finally found the problem, almost accidentally.

    The problem was in my destructor. I had:

    Qt Code:
    1. delete myPointer;
    2. myPointer = 0;
    To copy to clipboard, switch view to plain text mode 

    For some reason, the delete statement was causing a crash. I switched the two lines around, and now everything works.
    I think it has to do with the way I assigned the pointer. I had something like the following:

    Qt Code:
    1. somefunc()
    2. {
    3. MyClass myclass;
    4. myclass.myPointer = someOtherFunc();
    5. }
    To copy to clipboard, switch view to plain text mode 

    I'm *guessing* what happened is this:
    Inside someOtherFunc(), I create a new object on the heap and return it, which then gets assigned to myPointer. Then when somefunc() finishes, it tries to destroy myclass, which is on the stack. The destructor gets called, which then tries to delete the pointer, but I'm guessing at this stage the pointer is already invalid.

    Does this sound right? Sometimes pointers can be a bit confusing.
    Last edited by JovianGhost; 2nd June 2010 at 04:18.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program runs on Windows 7, crashes on Windows XP

    You switched the two lines around? So you now have something like the following?

    Qt Code:
    1. myPointer = 0;
    2. delete myPointer;
    To copy to clipboard, switch view to plain text mode 

    To me, that seems a little pointless.

  5. #5
    Join Date
    Mar 2010
    Posts
    55
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program runs on Windows 7, crashes on Windows XP

    Quote Originally Posted by fatjuicymole View Post
    You switched the two lines around? So you now have something like the following?

    Qt Code:
    1. myPointer = 0;
    2. delete myPointer;
    To copy to clipboard, switch view to plain text mode 

    To me, that seems a little pointless.
    Hm, now that I look at it, you're right. What was I thinking?

    I guess the root cause of all this is that something is wrong with my pointers. But I'm still confused as to why this is only a problem on XP and not 7.

    Looks like I'll have to rework things a bit...

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program runs on Windows 7, crashes on Windows XP

    The memory map will be different on XP and 7, but that should be invisible to the application, unless it does undefined things like trash memory or double free some pointers. On 7, you might be causing the same fault but because different code lives there, the same fault doesn't happen.

  7. #7
    Join Date
    Mar 2010
    Posts
    55
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program runs on Windows 7, crashes on Windows XP

    Ok, I found the problem.
    After spending DAYS troubleshooting this, and having the program crash in multiple locations, I finally traced it down to the root cause.

    At some points in the program, I would create a new pointer by static_cast'ing an existing pointer. The problem is I would then deallocate that new pointer, not realizing when I did so, I was also deallocating the ORIGINAL pointer. For some reason I thought that when I used static_cast I created a copy of the existing pointer.

    I went through my code and removed all relevant delete statements, and now all is well.

Similar Threads

  1. 64-bit Qt for windows: QtScript crashes.
    By eyeofhell in forum Qt Programming
    Replies: 38
    Last Post: 22nd January 2010, 15:18
  2. I need example for Windows Mobile working program
    By Mr.QT in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2009, 09:19
  3. Replies: 5
    Last Post: 5th October 2008, 05:12
  4. I can't compile my program in windows!!
    By brevleq in forum Qt Programming
    Replies: 12
    Last Post: 29th November 2007, 22:08

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
  •  
Qt is a trademark of The Qt Company.