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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:10:22+00:00 2026-05-16T12:10:22+00:00

I have a view that generates an image based on a series of layers.

  • 0

I have a view that generates an image based on a series of layers. I have images for the background, for the thumbnail, and finally for an overlay. Together, it makes one cohesive display.

It seems to work a dream, except for when it doesn’t. For seemingly no reason, I get an EXC_BAD_ACCESS on the specified line below after it’s generated somewhere between 8 and 20 images. I’ve run it through the memory leak tool and allocation tool, and it’s not eating up tons of memory and it’s not leaking. I’m totally stumped.

Here’s the relevant code:

- (UIImage *)addLayer:(UIImage *)layer toImage:(UIImage *)background atPoint:(CGPoint)point {
  CGSize size = CGSizeMake(240, 240);
  UIGraphicsBeginImageContext(size);

  [background drawAtPoint:CGPointMake(0, 0)];  // <--- error here
  [layer drawAtPoint:point];

  UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

  return result;
}


// Build the layered image -- thingPage onto thingBackground,
// then the screenshot on that, then the thingTop on top of it all.
// thingBackground, thingPage and thingTop are all preloaded UIImages.
-(UIImage *)getImageForThing:(Thing *)t {
  [self loadImageCacheIfNecessary];

  if (!t.screenshot) {
    return [UIImage imageNamed:@"NoPreview.png"];
  } else {
    UIImage *screenshot = t.screenshot;
    UIImage *currentImage = [self addLayer:thingPage toImage:thingBackground atPoint:CGPointMake(0, 0)];
    currentImage = [self addLayer:screenshot toImage:currentImage atPoint:CGPointMake(39, 59)];
    currentImage = [self addLayer:thingTop toImage:currentImage atPoint:CGPointMake(0, 1)]; 

    return currentImage;
  }
}

I can’t find anywhere that this is going wrong, and I’ve been tearing my hair out for a couple of hours on this. It’s the final known bug in the system, so you can imagine how antsy I am to fix it! 🙂

Thanks in advance for any help.

  • 1 1 Answer
  • 2 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-16T12:10:23+00:00Added an answer on May 16, 2026 at 12:10 pm

    As it turns out, the error wasn’t in the code I posted, it was in my caching of the thingBackground, thingPage and thingTop images. I wasn’t retaining them. Here’s the missing code, fixed:

    -(void)loadImageCacheIfNecessary {
      if (!folderBackground) {
        thingBackground = [[UIImage imageNamed:@"ThingBack.png"] retain];
      }
      if (!folderPage) {
        thingPage = [[UIImage imageNamed:@"ThingPage.png"] retain];
      }
      if (!folderTop) {
        thingTop = [[UIImage imageNamed:@"ThingTop.png"] retain];
      }
    }
    

    I will admit I’m still not comfortable with the whole retain/release/autorelease stuff in Objective C. Hopefully it’ll sink in one day soon. 🙂

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

Sidebar

Related Questions

I have a scrollview that automatically generates a series of subviews containing imageviews. The
So I have an .aspx view that dynamically adds validation images to the page
I have a large non-map image that I want to allow people to view
I'm trying generate a images/chart in my controller and have that image displayed in
I have a View based application for iPhone/iPod that plays audio, having a VU
I have a scrollview that automatically generates a series of subviews containing imageviews. The
I am beginner in rails. I have view that i try to print inside
I have a view that has a column to make it sortable. When clicking
I have a view that renders a list elements using the following template :
I have a view that shows user profile fields in a tabular format. There

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.