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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:19:59+00:00 2026-05-30T08:19:59+00:00

All, I am attempting to load a set of sounds asynchronously when I load

  • 0

All,

I am attempting to load a set of sounds asynchronously when I load a UIViewController. At about the same time, I am (occasionally) also placing a UIView on the top of my ViewController’s hierarchy to present a help overlay. When I do this, the app crashes with a bad exec. If the view is not added, the app does not crash. My ViewController looks something like this:

- (void)viewDidLoad
{
    [super viewDidLoad];

    __soundHelper = [[SoundHelper alloc] initWithSounds];

    // Other stuff
}

- (void)viewDidAppear:(BOOL)animated
    {
    // ****** Set up the Help Screen
    self.coachMarkView = [[FHSCoachMarkView alloc] initWithImageName:@"help_GradingVC" 
                                                    coveringView:self.view 
                                                     withOpacity:0.9 
                                                    dismissOnTap:YES 
                                                    withDelegate:self];

    [self.coachMarkView showCoachMarkView];
    [super viewDidAppear:animated];
}

The main asynchronous loading method of SoundHelper (called from ‘initWithSounds’) looks like this:

// Helper method that loads sounds as needed
- (void)loadSounds {

    // Run this loading code in a separate thread
    NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
    NSBlockOperation *loadSoundsOp = [NSBlockOperation blockOperationWithBlock:^{
        // Find all sound files (*.caf) in resource bundles
        __soundCache = [[NSMutableDictionary alloc]initWithCapacity:0];

        NSString * sndFileName;
        NSArray *soundFiles = [[NSBundle mainBundle] pathsForResourcesOfType:STR_SOUND_EXT inDirectory:nil];

        // Loop through all of the sounds found
        for (NSString * soundFileNamePath in soundFiles) {
            // Add the sound file to the dictionary
            sndFileName = [[soundFileNamePath lastPathComponent] lowercaseString];
            [__soundCache setObject:[self soundPath:soundFileNamePath] forKey:sndFileName];
        }

        // From: https://stackoverflow.com/questions/7334647/nsoperationqueue-and-uitableview-release-is-crashing-my-app
        [self performSelectorOnMainThread:@selector(description) withObject:nil waitUntilDone:NO];
    }];
    [operationQueue addOperation:loadSoundsOp];
}

The crash seems to occur when the block exits. The init of FHSCoachMarkView looks like this:

- (FHSCoachMarkView *)initWithImageName:(NSString *) imageName 
                           coveringView:(UIView *) view
                            withOpacity:(CGFloat) opacity
                           dismissOnTap:(BOOL) dismissOnTap
                           withDelegate:(id<FHSCoachMarkViewDelegate>) delegateID
{
    // Reset Viewed Coach Marks if User Setting is set to show them
    [self resetSettings];

    __coveringView = view;        
    self = [super initWithFrame:__coveringView.frame];
    if (self) {
        // Record the string for later reference
        __coachMarkName = [NSString stringWithString:imageName];
        self.delegate = delegateID;

        UIImage * image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]];

        // ****** Configure the View Hierarchy
        UIImageView *imgView = [[UIImageView alloc] initWithImage:image];

        [self addSubview:imgView];
        [__coveringView.superview insertSubview:self aboveSubview:__coveringView];

        // ****** Configure the View Hierarchy with the proper opacity
        __coachMarkViewOpacity = opacity;
        self.hidden = YES;
        self.opaque = NO;
        self.alpha = __coachMarkViewOpacity;

        imgView.hidden = NO;
        imgView.opaque = NO;
        imgView.alpha = __coachMarkViewOpacity;

        // ****** Configure whether the coachMark can be dismissed when it's body is tapped
        __dismissOnTap = dismissOnTap;

        // If it is dismissable, set up a gesture recognizer
        if (__dismissOnTap) {
            UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self 
                                                                                      action:@selector(coachMarkWasTapped:)];
            [self addGestureRecognizer:tapGesture];
        }
    }
    return self;
}

I have tried invoking the asynchronous block using both NSBlockOperation and dispatch_async and both have had the same results. Additionally, I’ve removed the aysnch call altogether and loaded the sounds on the main thread. That works fine. I also tried the solution suggested by @Jason in: NSOperationQueue and UITableView release is crashing my app but the same thing happened there too.

Is this actually an issue with the view being added in FHSCoachMarkView, or is it possibly related to the fact that both access mainBundle? I’m a bit new to asynch coding in iOS, so I’m at a bit of a loss. Any help would be appreciated!

Thanks,
Scott

  • 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-30T08:20:01+00:00Added an answer on May 30, 2026 at 8:20 am

    I figured this out: I had set up a listener on the SoundHelper object (NSUserDefaultsDidChangeNotification) that listened for when NSUserDefaults were changed, and loaded the sounds if the user defaults indicated so. The FHSCoachMarkView was also making changes to NSUserDefaults. In the SoundHelper, I was not properly checking which defaults were being changed, so the asynch sound loading method was being called each time a change was made. So multiple threads were attempting to modify the __soundCache instance variable. it didn’t seem to like that.

    Question: Is this the correct way to answer your own question? Or should I have just added a comment to the question it self?

    Thanks.

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

Sidebar

Related Questions

I am attempting to extract all instances of a particular format from a string:
I was attempting to store all the JMS object of the class Message recieved
I'm attempting to create a main js controller that includes all needed js files
All this originated from me poking at a compiler warning message (C4267) when attempting
I'm attempting to use the #define directive to change all of ulong to unsigned
I'm attempting to replace a pattern in all my .aspx and .ascx file when
I'm attempting to build a project called DropThings but I am getting all these
Question in SSAS for y'all. I am attempting to define a One to Many
I'm attempting to create Data Access Layer for my web application. Currently, all datatables
I am attempting to load up an entire array of NSManagedObjects into an NSArray,

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.