What does this mean in debugging?

J

JoeC

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.
 
A

Andrew Poelstra

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.
 
J

JoeC

It means you are dereferencing NULL pointers.

Probably you should stop.

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;

}
 
J

JoeC

JoeC said:
[..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


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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top