Prev: Write 64bit?
Next: Scope error
From: JoeC on 24 Mar 2010 20:22 I am writing an object with an array. I have an array of bits based on a 2d grid. I declare the grid 1d array with a pointer because the array will change size eventually. But I create the array, assign all the elements to 0 then in an accesor function I want to change the values of inside the array. class bitmap{ BYTE * bits; .... bitmap::bitmap(void){ acc=16; dwn=16; bits = new BYTE[acc*dwn]; for(int lp =0; lp > (acc*dwn); lp++){ bits[lp]=0; } .... It crashes here void bitmap::mod(int ac, int dn, BYTE col){ bits[(acc*dn)+ac] = col; <--Crashes. }
From: Ben Bacarisse on 24 Mar 2010 20:35 JoeC <enki034(a)yahoo.com> writes: > I am writing an object with an array. I have an array of bits based > on a 2d grid. I declare the grid 1d array with a pointer because the > array will change size eventually. But I create the array, assign all > the elements to 0 then in an accesor function I want to change the > values of inside the array. > > class bitmap{ > > BYTE * bits; > ... > > bitmap::bitmap(void){ > > acc=16; > dwn=16; > > bits = new BYTE[acc*dwn]; > > for(int lp =0; lp > (acc*dwn); lp++){ This won't do anything. You probably meant <. > bits[lp]=0; > } > ... > > It crashes here > > void bitmap::mod(int ac, int dn, BYTE col){ > > bits[(acc*dn)+ac] = col; <--Crashes. The obvious answer is that acc*dn + ac > 255 or < 0. > } In fact, the problem may be somewhere else. There is not enough data to even hazard a guess, but using a memory checking tool like valgrind will help you find it faster. BTW, it's usually more helpful to say what actually happens rather than just "crashes". -- Ben.
From: JoeC on 31 Mar 2010 19:26 On Mar 24, 7:35 pm, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: > JoeC <enki...(a)yahoo.com> writes: > > I am writing an object with an array. I have an array of bits based > > on a 2d grid. I declare the grid 1d array with a pointer because the > > array will change size eventually. But I create the array, assign all > > the elements to 0 then in an accesor function I want to change the > > values of inside the array. > > > class bitmap{ > > > BYTE * bits; > > ... > > > bitmap::bitmap(void){ > > > acc=16; > > dwn=16; > > > bits = new BYTE[acc*dwn]; > > > for(int lp =0; lp > (acc*dwn); lp++){ > > This won't do anything. You probably meant <. > > > bits[lp]=0; > > } > > ... > > > It crashes here > > > void bitmap::mod(int ac, int dn, BYTE col){ > > > bits[(acc*dn)+ac] = col; <--Crashes. > > The obvious answer is that acc*dn + ac > 255 or < 0. > > > } > > In fact, the problem may be somewhere else. There is not enough data > to even hazard a guess, but using a memory checking tool like valgrind > will help you find it faster. BTW, it's usually more helpful to say > what actually happens rather than just "crashes". > > -- > Ben. I am having various problems with this program. I am not sure how to present the problem and in some cases where to look. I am trying to do create a bitmap and there are some parts of what I am doing I don't fully understand or where to go to get what I am looking for. thanks.
From: JoeC on 31 Mar 2010 20:36 On Mar 31, 6:26 pm, JoeC <enki...(a)yahoo.com> wrote: > On Mar 24, 7:35 pm, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: > > > > > JoeC <enki...(a)yahoo.com> writes: > > > I am writing an object with an array. I have an array of bits based > > > on a 2d grid. I declare the grid 1d array with a pointer because the > > > array will change size eventually. But I create the array, assign all > > > the elements to 0 then in an accesor function I want to change the > > > values of inside the array. > > > > class bitmap{ > > > > BYTE * bits; > > > ... > > > > bitmap::bitmap(void){ > > > > acc=16; > > > dwn=16; > > > > bits = new BYTE[acc*dwn]; > > > > for(int lp =0; lp > (acc*dwn); lp++){ > > > This won't do anything. You probably meant <. > > > > bits[lp]=0; > > > } > > > ... > > > > It crashes here > > > > void bitmap::mod(int ac, int dn, BYTE col){ > > > > bits[(acc*dn)+ac] = col; <--Crashes. > > > The obvious answer is that acc*dn + ac > 255 or < 0. > > > > } > > > In fact, the problem may be somewhere else. There is not enough data > > to even hazard a guess, but using a memory checking tool like valgrind > > will help you find it faster. BTW, it's usually more helpful to say > > what actually happens rather than just "crashes". > > > -- > > Ben. > > I am having various problems with this program. I am not sure how to > present the problem and in some cases where to look. I am trying to > do create a bitmap and there are some parts of what I am doing I don't > fully understand or where to go to get what I am looking for. > > thanks. I have been going through my program and trying to find flaws. I am finding some and getting it to run. Most of my problems deal with a simple array using dynamic memory. I can do that or a vector. I do need it to change sizes because I will make the graphic expandable where I can put multiple icons on the same graphic. I have done this program before now I am adding color bitmaps instead of monochrome.
|
Pages: 1 Prev: Write 64bit? Next: Scope error |