Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. MSVC & MinGW
Forum Updated to NodeBB v4.3 + New Features

MSVC & MinGW

Scheduled Pinned Locked Moved Solved C++ Gurus
6 Posts 3 Posters 2.8k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by
    #1

    Hello everyone,

    I recently spend an ungodly amount of time searching for an memory access violation error that only accured when compiled with MSVC2015.

    Turns out I forgot to set a Pointer back to NULL after deleting the object ... Silly me.

    Somehow this was not a problem with MinGW. Does the MinGW compiler automatically set the Pointer to NULL if you call deleteLater()? That would explain a lot.


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    K JKSHJ 2 Replies Last reply
    0
    • J.HilkJ J.Hilk

      Hello everyone,

      I recently spend an ungodly amount of time searching for an memory access violation error that only accured when compiled with MSVC2015.

      Turns out I forgot to set a Pointer back to NULL after deleting the object ... Silly me.

      Somehow this was not a problem with MinGW. Does the MinGW compiler automatically set the Pointer to NULL if you call deleteLater()? That would explain a lot.

      K Offline
      K Offline
      Konstantin Tokarev
      wrote on last edited by
      #2

      No. Such behavior would violate C++ standard and cannot be expected from any reasonable compiler.

      What you are probably seeing is use-after-free, which in case of MinGW somehow works because old memory hasn't been overwritten yet, and in case of MSVC it gets overwritten fast enough to reveal the bug

      1 Reply Last reply
      3
      • J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        Thanks for the clarification!
        That is actually more in line with my original reasoning: "This is just happenstance." ;-)

        I'll mark it as sloved, thanks again.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          Hello everyone,

          I recently spend an ungodly amount of time searching for an memory access violation error that only accured when compiled with MSVC2015.

          Turns out I forgot to set a Pointer back to NULL after deleting the object ... Silly me.

          Somehow this was not a problem with MinGW. Does the MinGW compiler automatically set the Pointer to NULL if you call deleteLater()? That would explain a lot.

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @J.Hilk said in MSVC & MinGW:

          I recently spend an ungodly amount of time searching for an memory access violation error

          A debugger would have found the source of the error fairly quickly.

          • For MinGW, use GDB (already included in the copy of MinGW that's bundled with Qt).
          • For MSVC, use CDB (installed separately)

          If you're working on a *nix machine, Valgrind is a tool designed specifically to detect memory errors like this.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          J.HilkJ 1 Reply Last reply
          1
          • JKSHJ JKSH

            @J.Hilk said in MSVC & MinGW:

            I recently spend an ungodly amount of time searching for an memory access violation error

            A debugger would have found the source of the error fairly quickly.

            • For MinGW, use GDB (already included in the copy of MinGW that's bundled with Qt).
            • For MSVC, use CDB (installed separately)

            If you're working on a *nix machine, Valgrind is a tool designed specifically to detect memory errors like this.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #5

            @JKSH
            I actually used a debugger, the problem was, my program was halted not on the right spot but at random places in my code.
            I halted on *List.clear() .List is a list of pointers and List itself is a class, member and allocated on the stack. So I checked everything that was connected to the list and the objects it pointed to.
            The error itself that I later fixed was 10-20 lines above this entry...


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            JKSHJ 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @JKSH
              I actually used a debugger, the problem was, my program was halted not on the right spot but at random places in my code.
              I halted on *List.clear() .List is a list of pointers and List itself is a class, member and allocated on the stack. So I checked everything that was connected to the list and the objects it pointed to.
              The error itself that I later fixed was 10-20 lines above this entry...

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              @J.Hilk said in MSVC & MinGW:

              @JKSH
              I actually used a debugger, the problem was, my program was halted not on the right spot but at random places in my code.
              I halted on *List.clear() .List is a list of pointers and List itself is a class, member and allocated on the stack. So I checked everything that was connected to the list and the objects it pointed to.
              The error itself that I later fixed was 10-20 lines above this entry...

              Then a memory checker is our friend.

              I mentioned Valgrind in my previous post. It's not available on Windows, but Dr. Memory looks promising: http://www.drmemory.org/ (I haven't used this myself, though)

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved