Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]How to prevent this crash?
Forum Updated to NodeBB v4.3 + New Features

[Solved]How to prevent this crash?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 2.7k Views 1 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.
  • D Offline
    D Offline
    dolevo
    wrote on last edited by
    #1

    In my code, at a certain line I have this condition:

    @if(imageData->myImage==NULL)
    {
    ...
    }
    @

    However, my code crashes at the "if" line for a certain reason. It gives "read access violation" error. When I debug the code, I see in the locals and expressions that the value of the "imageData->myImage" is Memory access error. Could you please how I can put an if condition where I check if the memory is reachable for this variable or not?
    What I want to do is:

    @if(imageData->myImage== "Condition for memory access error")
    {
    ...
    }
    @

    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to DevNet.

      Did you check that imageData is a valid pointer ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Your myImage is probably declared as private, hence it's not accesible. Either make it public, or use a getter to get the pointer. Then the pointer == NULL will work (make sure you explicitly set it to null in the constructor or somewhere. Pointers, just like variables in c++, are not automatically initialised to 0).

        (Z(:^

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dolevo
          wrote on last edited by
          #4

          [quote author="SGaist" date="1363868284"]Hi and welcome to DevNet.

          Did you check that imageData is a valid pointer ?[/quote]

          How can I check it?

          [quote author="sierdzio" date="1363868421"]Your myImage is probably declared as private, hence it's not accesible. Either make it public, or use a getter to get the pointer. Then the pointer == NULL will work (make sure you explicitly set it to null in the constructor or somewhere. Pointers, just like variables in c++, are not automatically initialised to 0).[/quote]

          It's not declared as private. The code runs perfect for some time & passes million times over this line but it crashes there fore some reason.

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            Ah, ok. Then check for validity of imageData before using it:
            @
            if (imageData && imageData->myImage==NULL) {
            ...
            }
            @

            (Z(:^

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              As sierdzio said: check for imageData == NULL before doing imageData->myImage == NULL

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dolevo
                wrote on last edited by
                #7

                Of course. Why could I have thought about this before. Thanks guys. How do you mark the thread as solved?

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  Edit your initial post and add "[Solved]". I've already tagged it for you.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    You're welcome

                    Simply edit the thread title and add [Solved]

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dolevo
                      wrote on last edited by
                      #10

                      Thanks guys. You two are parallel processing here :D

                      1 Reply Last reply
                      0
                      • sierdzioS Offline
                        sierdzioS Offline
                        sierdzio
                        Moderators
                        wrote on last edited by
                        #11

                        Hehe, yes it would seem so :)

                        (Z(:^

                        1 Reply Last reply
                        0

                        • Login

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