Results 1 to 11 of 11

Thread: "Debug Assertion failed" in debug mode

  1. #1
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default "Debug Assertion failed" in debug mode

    I am having problem working in debug mode with QT 4.3.0
    Release works fine
    but when changing to debug mode i get on really innocent lines
    "Debug Assertion failed"

    this line for example:
    Qt Code:
    1. dataPath.toStdWString().c_str();
    To copy to clipboard, switch view to plain text mode 
    (used to be this line: CString searchPath = dataPath.toStdWString().c_str(); )

    it failes on the destructor of the temporary string.
    Has anyone ran into those problems?

    tnx,
    hed

    here is the stack:

    > MSVCR71D.dll!operator delete() + 0x99
    MSVCP71D.dll!std::collate<unsigned short>::do_hash() + 0x2b0
    MSVCP71D.dll!std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >::_Tidy() + 0x58
    MSVCP71D.dll!std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >::~basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >() + 0x13
    HiroClient.exe!HiroRTLogic_PC_Specific:eleteObsoleteFiles() Line 101 C++
    HiroClient.exe!HiroRTLogic_PC_Specific::BackSuppor tForOldVersions() Line 84 C++
    HiroClient.exe!HiroRTLogic::Init(HiroCodecContaine r * container=0x00538eb0, bool bFromMoviePlayback=false) Line 41 C++
    HiroClient.exe!CHiroClientApp::InitInstance() Line 181 + 0x4a C++
    mfc71ud.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00020c70, int nCmdShow=1) Line 39 + 0xb C++
    HiroClient.exe!wWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00020c70, int nCmdShow=1) Line 25 C++
    HiroClient.exe!wWinMainCRTStartup() Line 390 + 0x39 C
    kernel32.dll!RegisterWaitForInputIdle() + 0x49
    Last edited by jpn; 30th January 2008 at 09:48. Reason: missing tags

  2. #2
    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: "Debug Assertion failed" in debug mode

    Are you sure this is a Qt related problem? From what I see it is the STL runtime of MSVC that asserts... You are probably doing something you shouldn't be doing with the string.

  3. #3
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: "Debug Assertion failed" in debug mode - QString::toStdWString()

    It's this function thats the trigger:
    QString::toStdWString()

    it returns std::basic_string<wchar_t> which it creates inside - and in the destructor of the temporary object i fail.

    Again it's something that doesn't happen in the release. so i believe the code is ok,
    and has some mistaken Assertion in debug.

    it's rather a straightforward thing so i thought other here might be familiar with it.

    hed

  4. #4
    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: "Debug Assertion failed" in debug mode - QString::toStdWString()

    Quote Originally Posted by hed View Post
    It's this function thats the trigger:
    QString::toStdWString()
    QString just creates an object and doesn't care about it any more. Take a look at the stack trace you provided - there is not a single reference to Qt code there.

    Again it's something that doesn't happen in the release. so i believe the code is ok,
    and has some mistaken Assertion in debug.
    Because release applications don't assert. But it doesn't mean the code is correct. If the assert is there, it's because of a reason, I think it is safe to assume STL implementors knew what they were doing.

  5. #5
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: "Debug Assertion failed" in debug mode

    i still think it is a QT problem - only now i can be more specific. ;-)
    The fact i have a crash just means something interenally is not stable inside the QString object.
    here is my test program:
    Qt Code:
    1. QString param = "1";
    2. QString test = QString("Test %1").arg(param);
    3. CString test2 = test.toStdString().c_str();
    To copy to clipboard, switch view to plain text mode 

    everything works ok.

    Qt Code:
    1. QString param = "111111111111111111111111";
    2. QString test = QString("Test %1").arg(param);
    3. CString test2 = test.toStdString().c_str();
    To copy to clipboard, switch view to plain text mode 

    third line fails because of the size of the arg.

    Can you reproduce it?
    (My environment is - Windows + MFC + ATL)
    Anyone familiar with it?

    hed
    Last edited by jpn; 30th January 2008 at 09:49. Reason: changed [i] to [code]

  6. #6
    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: "Debug Assertion failed" in debug mode

    You clearly have an invalid code. It's the same like if you wrote:
    Qt Code:
    1. QString str("xxxxx");
    2. char *cstr = str.toAscii().data();
    3. printf("%s\n", cstr);
    To copy to clipboard, switch view to plain text mode 
    Second line of the above code is invalid because data() returns a pointer to internal data of the byte array that gets destroyed immediately as it is a temporary object. From what I understand you are doing exactly the same in your code and Qt has nothing to do with it.

  7. #7
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: "Debug Assertion failed" in debug mode

    it depends when the temporary variable is being killed.
    the line:
    CString test2 = test.toStdString().c_str();
    copy the data before the temporary object is being killed and its memory released.

    anyway, to better show my problem:
    take a look at the following code:
    Qt Code:
    1. QString param = "111111111111111111111111";
    2. QString test = QString("Test %1").arg(param);
    3. test.toStdString();
    To copy to clipboard, switch view to plain text mode 

    third line fails.
    it's the destructor of the temprary object that fails.
    Again -
    there is a good chance i'm doing something wrong:
    only i don't see what.

    hed.

  8. #8
    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: "Debug Assertion failed" in debug mode

    The temporary object gets destroyed immediately after the statement it was created in is finished.

    If the std::strnig object is valid Qt has nothing more to do with it. Are you by any chance using VS6 to compile your project?

  9. #9
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "Debug Assertion failed" in debug mode

    Quote Originally Posted by wysota View Post
    Are you by any chance using VS6 to compile your project?
    That's imho the correct question

    Keep in mind that std::string and std::wstring are different regarding whether you compile the code in Debug or Release mode in every msvc version. So when you mix e.g. Release Qt and Debug Program or vice versa, you'll encounter a crash. But your linker should warn you about such things.
    But why you need crappy std::string/wstring at all?

  10. #10
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "Debug Assertion failed" in debug mode

    To add to this growing post, I have run into similar issues when using std::string on VS2005 in debug mode. When the scope destructors are called the program aborts in the ~Tidy( ) function. This is only using std::strings and no QStrings what-so-ever. However, when I ran the same code on VS2003 it works just fine. The program also runs fine in release mode. I definatly believe it has something with VS implementation of std::string in converting it into a c_str( ). I am using Qt v4.3.0 as well, but I have to link to data libraries that return std::string's so dont assume that all people can get away from "crappy std::string/wstring". We have to make due.

  11. #11
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: "Debug Assertion failed" in debug mode

    I am using .Net 2003
    and in my case it was a Debug/Release mixing

    i was compiling in debug mode while using the release QT libraries.
    when changing to the debug libraries everything returned to behave normal


    hed

Similar Threads

  1. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 17:48
  2. Debug mode Qt 4.3.2
    By oetzi in forum Newbie
    Replies: 3
    Last Post: 13th October 2007, 19:06
  3. What is debug mode for without MSVC?
    By firegun9 in forum Newbie
    Replies: 1
    Last Post: 5th September 2007, 18:21
  4. Unable to execute in Debug Mode
    By Kapil in forum Installation and Deployment
    Replies: 38
    Last Post: 5th April 2006, 08:27

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.