Announcement

Collapse
No announcement yet.

Toolbar - Memory Access Violation

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

  • Toolbar - Memory Access Violation

    This may be a case of "ICS" (Insufficient Code Shown), but I thought I would ask just in case until I can figure it out myself.

    Under Vista with PB 8.04 I have tracked down a bug that in debug shows that I tried to "access a invalid memory address" while creating my toolbar. I added some messageboxes to narrow it down.

    Code:
    MSGBOX FUNCNAME$ + $CR + STR$(HwndToolbar) + $CR + STR$(VARPTR(tbb(0)))
         HeapFree GetProcessHeap(), 0, BYVAL VARPTR(tbb(0))
    MSGBOX FUNCNAME$ + $CR + STR$(HwndToolbar) + $CR + STR$(VARPTR(tbb(0)))
         SendMessage hWndToolbar, %TB_ADDBUTTONS, %NUM_TBBUTTONS, BYVAL VARPTR(tbb(0))
    MSGBOX FUNCNAME$ + $CR + STR$(HwndToolbar) + $CR + STR$(VARPTR(tbb(0)))
    Now according to the messagboxes, I get values for HwndToolbar and VARPTR(tbb(0)) for the 1st two messageboxes but can not get to the 3rd because the crash occurs on my line for the SendMessage (as far as I know, but we all know, where the problem occurs may not be where it happened, so I am only guessing at the moment)

    So my question (unless I have to break down to demo) is, if there is something I am obviously doing wrong? or does the line
    Code:
         HeapFree GetProcessHeap(), 0, BYVAL VARPTR(tbb(0))
    Do something wrong? or am I accessing a location in the midst of change? or some other concept if my next line is
    Code:
         SendMessage hWndToolbar, %TB_ADDBUTTONS, %NUM_TBBUTTONS,
    Again, I will go back and try to post example code if need be, but guessing code, I think something to do with the heap, and the next line is where debug catches it?
    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
    You are freeing the tbb array and the passing a reference to it:

    Code:
         HeapFree GetProcessHeap(), 0, BYVAL VARPTR(tbb(0))
         SendMessage hWndToolbar, %TB_ADDBUTTONS, %NUM_TBBUTTONS, BYVAL VARPTR(tbb(0))
    You must reverse the actions:

    Code:
         SendMessage hWndToolbar, %TB_ADDBUTTONS, %NUM_TBBUTTONS, BYVAL VARPTR(tbb(0))
         HeapFree GetProcessHeap(), 0, BYVAL VARPTR(tbb(0))
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      This code looks wrong:

      Code:
      HeapFree GetProcessHeap(), 0, BYVAL VARPTR(tbb(0))
      If tbb() is a PB array, it should not be freed manually as the compiler will handle deallocation.
      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

      Comment


      • #4
        Thanx Jose,
        I figured it had to be something simple and obvious that I was just not thinking of.
        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
          >> HeapFree GetProcessHeap(), 0, BYVAL VARPTR(tbb(0))

          >If tbb() is a PB array, it should not be freed manually as the compiler will handle >deallocation.

          You also may not assume HeapFree() against the process heap is the correct de-allocation function, as you don't know HOW the compiler allocated the memory.

          You should only be using HeapAlloc() and HeapFree() in pairs in your program, unless the product you are working with tells you otherwise..

          I only added the "unless" because I work with such a product... but that product ain't any of the PB compilers. (although my actual use is that I must ALLOCATE memory a certain way, because the product handles DE-allocation assuming I did so!)

          (Yes, that is kind of weird isn't it? As I mentioned, usually allocation and deallocation in a multi-product suite are handled by the same product).


          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X