What does this mean in debugging?

Discussion in 'C++' started by JoeC, Mar 31, 2010.

  1. JoeC

    JoeC Guest

    First-chance exception at 0x5b5dba37 (msvcr100d.dll) in Color
    Bitmap.exe: 0xC0000005: Access violation writing location 0x00000000.
    First-chance exception at 0x5b5dba37 (msvcr100d.dll) in Color
    Bitmap.exe: 0xC0000005: Access violation writing location 0x00000000.

    I am using VC++ express. I am trying to write a bitmap editor and I
    have been having all kinds of strage memory problems. I use a few
    pointers mainly the one that holds the array for bitmap bit data.
     
    JoeC, Mar 31, 2010
    #1
    1. Advertising

  2. On 2010-03-31, JoeC <> wrote:
    > First-chance exception at 0x5b5dba37 (msvcr100d.dll) in Color
    > Bitmap.exe: 0xC0000005: Access violation writing location 0x00000000.
    > First-chance exception at 0x5b5dba37 (msvcr100d.dll) in Color
    > Bitmap.exe: 0xC0000005: Access violation writing location 0x00000000.
    >
    > I am using VC++ express. I am trying to write a bitmap editor and I
    > have been having all kinds of strage memory problems. I use a few
    > pointers mainly the one that holds the array for bitmap bit data.


    It means you are dereferencing NULL pointers.

    Probably you should stop.

    --
    Andrew Poelstra
    http://www.wpsoftware.net/andrew
     
    Andrew Poelstra, Mar 31, 2010
    #2
    1. Advertising

  3. JoeC

    JoeC Guest

    On Mar 31, 2:58 pm, Andrew Poelstra <>
    wrote:
    > On 2010-03-31, JoeC <> wrote:
    >
    > > First-chance exception at 0x5b5dba37 (msvcr100d.dll) in Color
    > > Bitmap.exe: 0xC0000005: Access violation writing location 0x00000000.
    > > First-chance exception at 0x5b5dba37 (msvcr100d.dll) in Color
    > > Bitmap.exe: 0xC0000005: Access violation writing location 0x00000000.

    >
    > > I am using VC++ express.  I am trying to write a bitmap editor and I
    > > have been having all kinds of strage memory problems.  I use a few
    > > pointers mainly the one that holds the array for bitmap bit data.

    >
    > It means you are dereferencing NULL pointers.
    >
    > Probably you should stop.
    >
    > --
    > Andrew Poelstrahttp://www.wpsoftware.net/andrew


    Thanks.

    I have this;

    delete [] bits;

    bits = new BYTE[acc*dwn];

    for(int lp =0; lp > (acc*dwn); lp++)
    bits[lp]=0;

    bits = flip();




    void bitmap::display(HDC hdc, int ac, int dw){

    HDC dc = CreateCompatibleDC(NULL);

    VOID *pvBits;

    HBITMAP hbitmap = CreateDIBSection(dc,&bInfo,
    DIB_RGB_COLORS,
    &pvBits,NULL,0 );

    CopyMemory(pvBits, bits, (acc*dwn));

    SelectObject(dc, hbitmap);
    BitBlt(hdc, ac, dw, 16, 16 ,dc, 0, 0, SRCCOPY);
    DeleteDC(dc);

    }

    BYTE* bitmap::flip(){

    BYTE * temp = new BYTE[acc*dwn];

    for (int index=0; index < dwn; index++)
    memcpy(&temp[((dwn-1) - index)*acc],
    &bits[index*acc], acc);


    return temp;

    }
     
    JoeC, Apr 1, 2010
    #3
  4. JoeC

    JoeC Guest

    On Apr 1, 8:01 am, Victor Bazarov <> wrote:
    > JoeC wrote:
    > > [..JoeC's program reports access violation..]
    > > I have this;

    >
    > >    delete [] bits;

    >
    > >    bits = new BYTE[acc*dwn];

    >
    > So, we're to assume 'bits' is declared as BYTE*, yes?  Do you know if
    > this allocation succeeds?  On some older compilers (not compliant now)
    > you would get NULL in the pointer instead of an exception when
    > allocation fails.  How big a chunk are you requesting?  What's the value
    > of 'acc*dwn'?
    >
    >
    >
    > >    for(int lp =0; lp > (acc*dwn); lp++)

    >
    > You do?  How does it work?  I suppose your loop never executes, and you
    > don't even know it...
    >
    > >               bits[lp]=0;

    >
    > >            bits = flip();

    >
    > Now, here you replace the value of 'bits' with whatever 'flip' returns.
    >   Does it return the same pointer?  If not, you've just lost your
    > allocated memory - that's a memory leak.  Not such a huge deal, of
    > course, but you might consider preserving the pointer and deallocating
    > it after assigning 'bits' its new value.  What is also likely that, if
    > 'flip()' yields NULL, then you just made your pointer point to invalid
    > memory.  As soon as you try accessing it (for reading or for writing),
    > you're likely to get the access violation.
    >
    >
    >
    > > void bitmap::display(HDC hdc, int ac, int dw){

    >
    > >    HDC dc = CreateCompatibleDC(NULL);

    >
    > >    VOID *pvBits;

    >
    > >    HBITMAP hbitmap = CreateDIBSection(dc,&bInfo,
    > >                                 DIB_RGB_COLORS,
    > >                                 &pvBits,NULL,0 );

    >
    > >    CopyMemory(pvBits, bits, (acc*dwn));

    >
    > Well, this function is not known in C++ (It's Windows API or?), so we
    > don't know how 'bits' is manipulated there, you might consider telling
    > us those details.
    >
    >
    >
    > >    SelectObject(dc, hbitmap);
    > >    BitBlt(hdc, ac, dw, 16, 16 ,dc, 0, 0, SRCCOPY);
    > >    DeleteDC(dc);

    >
    > > }

    >
    > > BYTE* bitmap::flip(){

    >
    > >   BYTE * temp = new BYTE[acc*dwn];

    >
    > >   for (int index=0; index < dwn; index++)
    > >    memcpy(&temp[((dwn-1) - index)*acc],
    > >           &bits[index*acc], acc);

    >
    > Unless you somehow fudged up the pointer arithmetic (which at the first
    > sight doesn't seem that), this should be OK if 'bits' has a valid
    > pointer value.  Does it?
    >
    >
    >
    > >   return temp;

    >
    > OK, so you get your 'bits' to participate in the 'flipping' and you
    > assign the result to it.  Perhaps not so bad, so the error can be elsewhere.
    >
    >
    >
    > > }

    >
    > So, which line causes the access violation?  Any of the ones you've posted?
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask



    Thanks a great deal. I got rid of the flip and changed the way I do
    the graphics. I am still working on different parts of the program
    its still acting weird.

    acc and dwn are 16 so my block is only 255 elements across and memory
    should not be an issue. Now I have other challenges like setting the
    colors but I will do what I can. Because I set the palet then I
    chagne the value in the bits array. That seems to work but it crashed
    when I try to change the colors:

    void bitmap::setColor(int n, BYTE r, BYTE g, BYTE b){

    bInfo.bmiColors[n].rgbBlue = b;
    bInfo.bmiColors[n].rgbGreen = g;
    bInfo.bmiColors[n].rgbRed = r;
    bInfo.bmiColors[n].rgbReserved = 0;

    }

    Nearly Identical code worked in my constructor.

    Is there a link to the FAQ? I do appreciate the help and don't want
    to annoy people.
     
    JoeC, Apr 1, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johann Blake
    Replies:
    1
    Views:
    1,215
    Hermit Dave
    Jan 5, 2004
  2. jacob navia

    Debugging C vs debugging C++

    jacob navia, Oct 26, 2006, in forum: C Programming
    Replies:
    11
    Views:
    602
    Ian Collins
    Oct 27, 2006
  3. Li Ma
    Replies:
    1
    Views:
    2,314
    Roedy Green
    Mar 9, 2009
  4. Rahul
    Replies:
    4
    Views:
    605
    Robert Kern
    Apr 7, 2009
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,233
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page