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 6085823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:40:56+00:00 2026-05-23T11:40:56+00:00

for my game iOS project I need a ring buffer. It should work similar

  • 0

for my game iOS project I need a ring buffer. It should work similar to a queue where elements go out and go in but the total amount of elements in the buffer should stay the same.

I implemented the ring buffer successfully using java but I am not so familar with objective-c. I found a ring buffer implementation on the web called CHCircularBuffer: https://bitbucket.org/devartum/chdatastructures/src/4d6d7194ee94/source/CHCircularBuffer.m However I failed implementing it correctly.

The circular buffer is a property of a class called TerrainManager which does all the mathematical terrain generation.

@interface TerrainManager : NSObject{

    int terrainParts;

    CHCircularBuffer* circularTerrainBuffer;
}

@property(nonatomic, retain) CHCircularBuffer *circularTerrainBuffer;
@end

This how the ring buffer is initialized in the implementation of TerrainManager

circularTerrainBuffer = [[CHCircularBuffer alloc] initWithCapacity:parts];

This creates an instance of the buffer and sets the size property to parts. Now I add objects to the buffer using addObject method:

[circularTerrainBuffer addObject:[NSNumber numberWithDouble:0.2]];

Sometimes this line receives an error “exec_bad_access”. E.g. when I init the buffer with capacity of 15 everything is fine, with 20 I get the error.

I now try to access the buffer from the terrain class where the drawing takes place. But whenever I try to access the objects I get an “bad_access” error.

NSArray *arr = [terrainManager.circularTerrainBuffer allObjects];

E.g. this line would create the error.

So there is something wrong with my code. Maybe I dont understand the buffer and add objects the wrong way. I dont know. Any ideas or suggestions?

  • 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-23T11:40:57+00:00Added an answer on May 23, 2026 at 11:40 am

    The snippets of code you are showing are correct. I implemented a small project to test CHCircularBuffer the way you specify and it works correctly. So, the problem must be somewhere else.

    The only way around this is, IMHO, put a breakpoint on the line that fails and step into the addObject function to see where exactly it fails. The array could be reallocated in there, so may be this is failing and giving the bad access. The same for allObjects.

    Anyway, I have to say that I could execute my test without any issue, adding objects, removing them from head and tail, and getting the array of all objects with no issues.

    If you post more code, we can maybe help a bit more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I picked up this iOS app dev project for something to work
I'm developing a game for iOS that should include the multiplayer. It's not a
I'm currently working on an iOS game where, long story short, I need to
I'm diving into iOS development and am building a game that has multiple game
Possible Duplicate: Determine device (iPhone, iPod Touch) with iOS I am making a game
I am new to xcode/ios etc... and having a little trouble figuring out a
I'm thinking of writing a game. It's inspired by Minecraft/Terraria (but don't worry it
I write an Desktop/iOS Game with OpenGL and want to play audio files (mp3
I'm writing an iOS game (Using UIView), which has a randomly generated 2D city.
I have been developing a simple game for iOS which involves dragging and using

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.