Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7167737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:38:15+00:00 2026-05-28T14:38:15+00:00

I’m attempting to set up a simple Mac-based 2D tiling engine, using a 2D

  • 0

I’m attempting to set up a simple Mac-based 2D tiling engine, using a 2D NSMutableArray for mapping purposes. I am using a subclass of NSViewController with a reference to the map object (which contains said array) and passing drawing requests for tile data through it to the map in the interests of maintaining MVC integrity. However, my application seems to not be populating the array with objects before my drawRect code begins firing.

Every time I run this app as written, my window fails to load and I receive the error message “-[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array” in the debugger. As far as I can tell, my array should be completely initialized with zeroes before the view is actually displayed or needs to be drawn.

Here is the -loadView method from my NSViewController subclass:

- (void)loadView
{
    currentMap = [[TestMap alloc] init];
    [super loadView];
}

and here is the init method from my map object:

- (id)init
{
    dimensions = NSMakeSize(15.0,20.0);
    tileset = [[TestTileset alloc] init];
    map = [NSMutableArray arrayWithCapacity:15];
    for (int i = 0; i == 14; i++)
    {
        NSMutableArray *tempRow = [NSMutableArray arrayWithCapacity:20];
        for (int j = 0; j == 19; i++)
        {
            NSNumber *tempID = [NSNumber numberWithInt:0];
            [tempRow addObject:tempID];
        }
        [map addObject:tempRow];
    }
    return self;
}

Judicious use of breakpoints has indicated that

[super loadView]

is somehow being called before init begins its for loops – and obviously, my drawRect code which has to reference the array follows on from there and fails quickly. I must be doing something wrong or out of order, but I cannot figure out what it might be.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:38:15+00:00Added an answer on May 28, 2026 at 2:38 pm

    You have == instead of !=, so neither of your for loops executes. I think the loops should be as follows:

    for (int i = 0; i != 15; i++)
    {
        NSMutableArray *tempRow = [NSMutableArray arrayWithCapacity:20];
        for (int j = 0; j != 20; j++)
        {
            NSNumber *tempID = [NSNumber numberWithInt:0];
            [tempRow addObject:tempID];
        }
        [map addObject:tempRow];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.