Confused as to array behaviour

Posts: 306
Joined: 2009.03
Post: #1
BitmappedFont *defaultFont=[[BitmappedFont alloc]
initWithFontFilename:@"font.png" fontWidth:16 fontHeight:16];
self.fonts=[NSMutableArray array];
[self.fonts addObject:defaultFont];

where @property(nonatomic,retain)NSMutableArray *fonts;
with: NSMutableArray *fonts; as the decleration

It breaks when im trying to use that array. My program worked fine before I added that, and it works fine if i comment it out. I use arrays all over the place so I don't understand why this one is breaking. Its just the generic objc exception and it happens on the addObject call. Its acting like the function isn't there or something. I tried changing it to [[NSMutableArray alloc] init] but it still had issues.
Any ideas?
Quote this message in a reply
Posts: 34
Joined: 2009.01
Post: #2
You've @synthesized the 'fonts' property, I assume?
Quote this message in a reply
Posts: 306
Joined: 2009.03
Post: #3
Yeah. Im wondering what sorta of memory mistakes can cause random things to break in other parts of the code that might account for this.
Quote this message in a reply
Posts: 306
Joined: 2009.03
Post: #4
I think i know whats going on. In the constructor of that bitmap font thing it was doing this:
-(void) createFontGrid
//the font texture has 16 rows
const float rows = 16.0f;
//The font texture has 16 columns
const float columns = 16.0f;
const float xoffset = 1.0f / columns;
const float yoffset = 1.0f / rows;

//prebuild the texture coordinates array for all characters
for(int i=0;i<256;i++)
const float cx = (float)(i % 16) * xoffset;
const float cy = (float)(i / 16) * yoffset;
const int index = i * 16;
m_textureCoordinates[ index ] =/*FFF*/ cx;
m_textureCoordinates[index+1] =/*FFF*/ 1 - cy - yoffset;
m_textureCoordinates[index+2] =/*FFF*/ cx + xoffset;
m_textureCoordinates[index+3] =/*FFF*/ 1 - cy - yoffset;
m_textureCoordinates[index+4] =/*FFF*/ cx + xoffset;
m_textureCoordinates[index+5] =/*FFF*/ 1 - cy;
m_textureCoordinates[index+6] =/*FFF*/ cx;
m_textureCoordinates[index+7] =/*FFF*/ 1 - cy;


If i comment that out it is ok. So i prob went out of bounds on some memory or something. I convereted it from 8 to 16 rows(got this code from somewhere) so I prob botched it. Anyhow thanks for looking whoever did I will figure it out.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Confused with array-ness Tobs_ 4 3,119 Aug 12, 2007 05:37 PM
Last Post: JeroMiya
  Weird behaviour with structs and the = operand Jones 2 2,521 Oct 12, 2006 07:11 PM
Last Post: Jones
  memcpy(stuct array pointer struct array point) unknown 22 10,253 Sep 29, 2005 03:16 PM
Last Post: unknown
  Confused While Debugging Nick 2 3,194 Feb 24, 2005 10:04 AM
Last Post: Nick