Recent

Author Topic: EXC_BAD_Access with record array  (Read 5676 times)

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
EXC_BAD_Access with record array
« on: December 06, 2011, 06:18:51 am »

Hi all,
I have a record like that,

Type
  TIColor = record
      red: Byte;
      green: Byte;
      blue: Byte;
  end;

  TBmp = record
      Bmp : TBGRABitmap;
      bwidth : integer;
      bheight : integer;
      a: Float;
      pcolor: array of array of TIColor;
    end;

When i use the following code I got the EXC_BAD_ACCESS error. Can someone figure it out?

        bmpArray[k].pcolor[j,i].red:=newp.red;

Thanks.

Bart

  • Hero Member
  • *****
  • Posts: 5691
    • Bart en Mariska's Webstek
Re: EXC_BAD_Access with record array
« Reply #1 on: December 06, 2011, 10:41:31 pm »
Forgot to initialize tha array (using setlength)?

Bart

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: EXC_BAD_Access with record array
« Reply #2 on: December 07, 2011, 02:53:01 pm »

Thanks Bart for the reply,
I have tried the setlength case, like this setlength(bmpArray,3) but same result.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: EXC_BAD_Access with record array
« Reply #3 on: December 07, 2011, 03:40:06 pm »
What is EXC_BAD_ACCESS and the causes. So it looks like the code fragment is not enough. What is the type of bmpArray? array of TBmp? If so, and you have SetLength-ed it, have you SetLength-ed bmpArray[k].pcolor? pcolor is another dynamic array you know...

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: EXC_BAD_Access with record array
« Reply #4 on: December 07, 2011, 03:51:49 pm »
And what is newp? If newp is a non-initialised pointer then you have the same problem.

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: EXC_BAD_Access with record array
« Reply #5 on: December 07, 2011, 05:40:48 pm »

@Leledumbo
Exactly, bmparray is array of TBmp and like this,
    bmpArray: array of TBmp;

@ludob
 Here is newp: TBGRAPixel;

In this line, it gives that error.
 bmpArray[k].pcolor[j,i].red:=newp.red;

P.S
     SetLength(bmpArray, 3);
     is used for.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: EXC_BAD_Access with record array
« Reply #6 on: December 07, 2011, 06:16:29 pm »
Quote
have you SetLength-ed bmpArray[k].pcolor?

You should also have something like this:

Code: [Select]

for k:=low(bmpArray) to high(bmpArray) do
    begin
    SetLength(bmpArray[k].pcolor,4);
    for j:=low(bmpArray[k].pcolor) to high(bmpArray[k].pcolor) do
      SetLength(bmpArray[k].pcolor[j],5);
    end;

 

TinyPortal © 2005-2018