Announcement

Collapse
No announcement yet.

Invalid Memory Location

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Invalid Memory Location

    I know this is hard to track down, but if I have a block of code that crashes in debug that I accessed an invalid memory location, but the same code in my attempt to demo does not, is there a way to let the debugger point me WHERE it happened?????

    (Maybe PB9 when I get it)

    With PB8, I place a messagebox 1 line before where I think is the cause (because Run to Caret only seems to work if the program is one *.bas file and not multiple *.inc files), and let it animate from there, so I can try to find WHAT or WHERE the faulty code lies

    Before anyone says "Code Not Shown" :wavey:
    Like I said, the same code in demo does not fail.....so all I can show is working code....but if it helps somehow??? I will....If not, I am still working on trying to demo a failure...but like I said, if there is some way in debug that can track the code? (currently what would be 2 functions in animate, in the large project has been running for 20 minutes and I have YET to get to where the debugger says I accessed an invalid memory location)

    My other route does not work either to log all runtime errors, because I hit the error, it does not jump to my routine to write the error to a log file, so I feel hopelessly stuck again
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    Can you log the messages?
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment


    • #3
      FWIW in this type of situation where the fault lies "somewhere" in a block of code, rather than rely on the debugger, I insert messageboxes immediately before each possible candidate, not forgetting to use the %MB_APPMODAL style so that they actually stop the application.

      Sometimes messageboxes are an embarrassment, for example where you are trying to debug a WM_PAINT or WM_ERASEBKGND handler. In this case it is very useful to set the text of a handy dialog caption (quite often the parent has a caption) to show what is going on.

      BEEP is rather handy too.

      Comment


      • #4
        Thanx for the warning Chris...(I too have found problems with MsgBox route either eluding or stopping the problem all together....but I totally forget the %MB_APPMODAL part)

        BEEP is rather handy too
        How would I use that??? it only does me good if I know where I am when the error occurrs

        Rodney...nope not to my knowledge....I have routines to log, but either I am missing a concept or something, but the closest I can get is to log all function calls, and try to figure out Why it stopped logging??? (and even that takes longer than debug due to read write times)

        One thing I am trying now is (now that I got my best guess working) is the set breakpoint, and then animate.

        Anyways, thanx for the input...I am working on it....

        For those wanting to know...my problems lie with the RichEdit, and streaming RTF into it...but my gut instinct is telling me that I will find loading from file is pointing beyond the end of the file??? (Just guessing at the moment, but I hope to know after another half hour (if my tracking the cursor position works) If not, then I gotta find some way to track this)
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          The only debugging tool I use -> TRACE !!!

          James

          Comment


          • #6
            Unfortunately bad timing on my behalf, I missed the event to see if my guess was right, but when I came back the debugger was no longer running, and the log window at the bottom of PB read as:
            Began Debug at 6:45:11 PM on 8/26/2008
            Exception: Memory Access Violation
            Program tried to read or write to an invalid memory address
            End Debug at 7:38:19 PM on 8/26/2008
            Hmmm at this point I have to think of how to tear down more of the original code so a demo of the problem can help so I can show code....right now its allllll guesswork
            Engineer's Motto: If it aint broke take it apart and fix it

            "If at 1st you don't succeed... call it version 1.0"

            "Half of Programming is coding"....."The other 90% is DEBUGGING"

            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

            Comment


            • #7
              The simple answer to your question is, "no"

              Pure and simple, sometimes you can do something either silly or naughty and you won't see any feedback for hundreds or thousands of lines of code.

              However, memory access error will give immediate GPF BUT... you need to compile with #DEBUG ERROR OFF or the compiler will catch array bounds and null pointer errors and never execute the offending statement.

              So TRACE + #DEBUG ERROR OFF is where to start, but not in stepping debugger because that uses #DEBUG ERROR ON regardless of metastatements.
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Thank you for that reminder JC
                doing that I got the following (not that it means much at the moment, but)
                RICHCOM_EDITSTREAMINCALLBACK($<00>¢<02>QYK<00><ýJ<00>,3546980,4092,1233004)
                RICHCOM_EDITSTREAMINCALLBACK Exit
                RICHCOM_EDITSTREAMINCALLBACK($<00>¢<02>QYK<00>8<0D>K<00>,3546980,4092,1233004)
                RICHCOM_EDITSTREAMINCALLBACK Exit
                RICHCOM_EDITSTREAMINCALLBACK($<00>¢<02>QYK<00>4<1D>K<00>,3546980,4092,1233004)
                RICHCOM_EDITSTREAMINCALLBACK Exit
                RICHCOM_EDITSTREAMINCALLBACK($<00>¢<02>QYK<00>0-K<00>,3546980,4092,1233004)
                RICHCOM_EDITSTREAMINCALLBACK Exit
                RICHCOM_EDITSTREAMINCALLBACK($<00>¢<02>QYK<00>,=K<00>,3546980,4092,1233004)
                RICHCOM_EDITSTREAMINCALLBACK Exit
                RICHCOM_EDITSTREAMINCALLBACK($<00>¢<02>QYK<00>(MK<00>,3546980,4092,1233004)
                RICHCOM_EDITSTREAMINCALLBACK Exit
                I kept it short to the last few inputs until I get a chance to see what each of the values actually mean.....
                Engineer's Motto: If it aint broke take it apart and fix it

                "If at 1st you don't succeed... call it version 1.0"

                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                Comment


                • #9
                  MCM...I think I missed the difference in Debug Error ON or OFF concepts (aka the docs confusing me, or been troubleshooting too long)
                  but the below is the last of the trace of using your option to turn debug error off
                  RICHCOM_EDITSTREAMINCALLBACK($<00>Ì<02>QYK<00><ýJ<00>,11964460,4092,1233004)
                  RICHCOM_EDITSTREAMINCALLBACK Exit
                  RICHCOM_EDITSTREAMINCALLBACK($<00>Ì<02>QYK<00>8<0D>K<00>,11964460,4092,1233004)
                  RICHCOM_EDITSTREAMINCALLBACK Exit
                  RICHCOM_EDITSTREAMINCALLBACK($<00>Ì<02>QYK<00>4<1D>K<00>,11964460,4092,1233004)
                  RICHCOM_EDITSTREAMINCALLBACK Exit
                  RICHCOM_EDITSTREAMINCALLBACK($<00>Ì<02>QYK<00>0-K<00>,11964460,4092,1233004)
                  RICHCOM_EDITSTREAMINCALLBACK Exit
                  RICHCOM_EDITSTREAMINCALLBACK($<00>Ì<02>QYK<00>,=K<00>,11964460,4092,1233004)
                  RICHCOM_EDITSTREAMINCALLBACK Exit
                  RICHCOM_EDITSTREAMINCALLBACK($<00>Ì<02>QYK<00>(MK<00>,11964460,4092,1233004)
                  RICHCOM_EDITSTREAMINCALLBACK Exit
                  First glance they look the same....but maybe someone spots something I don't???
                  Engineer's Motto: If it aint broke take it apart and fix it

                  "If at 1st you don't succeed... call it version 1.0"

                  "Half of Programming is coding"....."The other 90% is DEBUGGING"

                  "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                  Comment


                  • #10
                    There's just no way of telling without seeing the code. You're probably reading past the end of the read buffer for EM_STREAMIN, so it's a good idea to put the stream code in a test program, and run a few, er, tests
                    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                    Comment


                    • #11
                      Cliff, I don't know where you are starting from, but there are a couple of examples here which I found helpful with streaming, in particular Charles Dietz's: http://www.powerbasic.com/support/pbforums/showthread.php?t=24937

                      Comment


                      • #12
                        You might also look at the IsBad[Read|Write]Ptr () functions .

                        Then again, as I said before... just because your program goes belly-up in your stream callback procedure does not mean that's where your error is - it's just where an earlier error actually takes that bite out of a tender body part.

                        FWIW, that 'read (or write) beyond buffer limit' idea sounds very promising. But testing the pointer with IsBadxxxPtr won't help if the buffer you are passing is a LOCAL variable (and probably not if STATIC or GLOBAL either) (code not shown), since for sure you own the stack (LOCAL) and probably own enough data segment (STATIC or GLOBAL) that you will have permission to read/write at the target address, even though you don't really want to.
                        Last edited by Michael Mattias; 27 Aug 2008, 08:05 AM.
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Code Shown

                          Ok guys, I FINALLLLLLLYYYY got an example that demonstrates my problem.

                          So far my process to replicate was
                          1. Use an EXCELLLENT example from Edwin Knoppert that allows you to have pictures in RTF seen in Richedit. (Works perfect)
                          2. I added 2 more Richedits, (one via API and one via DDT) to compare if either of them would cause the problem. (Works Perfect)
                          3. Added a subclass for catching keystrokes in the richedit just like in my large project, (again....Works Perfect)
                          4. Added Trace to find out why I am still getting away with working perfect?...(HMMMM nowwwww I get an Invalid Memory location???)
                          5. Went back to Edwin's original example and added Trace and wouldn't you know it....Invalid Memory Location!!!!
                          6. Take the trace away....No Problems


                          To replicate the problem, See Attached (Hint subtly accepted, and almost took a baseball bat to my self deleting the in-line code)
                          Attached Files
                          Last edited by Cliff Nichols; 27 Aug 2008, 10:49 AM. Reason: Change to Attachment
                          Engineer's Motto: If it aint broke take it apart and fix it

                          "If at 1st you don't succeed... call it version 1.0"

                          "Half of Programming is coding"....."The other 90% is DEBUGGING"

                          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                          Comment


                          • #14
                            >Added a subclass for catching keystrokes in the richedit ....

                            Why?

                            WM_COMMAND/EN_CHANGE reports changes in the control's contents by whatever means (not just keystrokes). Unless you are planning on doing something else...(code not shown).....

                            Probably moot but..
                            Code:
                            SELECT CASE CBMSG
                                CASE %WM_INITDIALOG
                                CASE %WM_SIZE
                            
                                    IF IsIconic( CBHNDL ) THEN EXIT SELECT
                            
                                    GetClientRect CBHNDL, R
                                    MoveWindow GetDlgItem( CBHNDL, 100 ), 0, 0, R.nRight, R.nBottom, 1
                            
                                CASE %WM_DESTROY
                                END SELECT
                            You are missing the required statements after the CASEs of both WM_INITDIALOG and WM_DESTROY. I usually use a "LOCAL dummy AS LONG" and assign a value in these cases.
                            Michael Mattias
                            Tal Systems Inc. (retired)
                            Racine WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Cliff,

                              Your example works fine here (8.04 XP Pro Sp3). No errors or gpf's. Of course I'm not using the same Test.rtf (you didn't provide it.).

                              No dif if Trace On/Off.

                              ==============================
                              "Everybody pities the weak;
                              jealousy you have to earn."
                              Arnold Schwarzenegger (1947-)
                              ==============================
                              Last edited by Gösta H. Lovgren-2; 27 Aug 2008, 09:15 AM. Reason: Clarity, not confusion.
                              It's a pretty day. I hope you enjoy it.

                              Gösta

                              JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                              LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                              Comment


                              • #16
                                Gosta, my bad.....I went back to my post and added the RTF file....maybe that will make the difference in replicating the problem?

                                So far I have been led from the debugger in animate that when I am alerted to an invalid memory location, is in the streamin function (still tracking what though)

                                Engineer's Motto: If it aint broke take it apart and fix it

                                "If at 1st you don't succeed... call it version 1.0"

                                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                                Comment


                                • #17
                                  At the size of that RTF, I think an "attachment" would have been a better choice than inline posting. Takes approximately forever to load and view this page.

                                  Fortunately, "edit" of posts is allowed, he subtly hinted.
                                  Michael Mattias
                                  Tal Systems Inc. (retired)
                                  Racine WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    Right you are MCM....I went back and changed it to a zip file. Thanks for the hint,
                                    Engineer's Motto: If it aint broke take it apart and fix it

                                    "If at 1st you don't succeed... call it version 1.0"

                                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                                    Comment


                                    • #19
                                      gracias, beaucoup better.
                                      Michael Mattias
                                      Tal Systems Inc. (retired)
                                      Racine WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        Originally posted by Cliff Nichols View Post
                                        Gosta, my bad.....I went back to my post and added the RTF file....maybe that will make the difference in replicating the problem?
                                        Cliff, As far as I can see the problem is in your rtf file. It opens another rtf just fine but gpfs when trying to open your rtf.

                                        I opened test.rtf in Word and deleted the graphic, and now your example runs fine, so the problem appears you can't load a graphic.

                                        ''<<<Added later>>> It doesn't seem to make any difference if Trace is ON or OFF. GPF's with the graphic.


                                        =========================================
                                        "The only way to get rid of a temptation
                                        is to yield to it."
                                        Oscar Wilde (1854-1900)
                                        =========================================
                                        Last edited by Gösta H. Lovgren-2; 27 Aug 2008, 12:58 PM. Reason: Added moxie
                                        It's a pretty day. I hope you enjoy it.

                                        Gösta

                                        JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                        LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                        Comment

                                        Working...
                                        X