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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:47:07+00:00 2026-05-28T00:47:07+00:00

I have a problem with a CATiledLayer. It is working perfect in on iOS

  • 0

I have a problem with a CATiledLayer. It is working perfect in on iOS 4, but has problems on iOS 5.

My Problem ist that drawRect is called twice for the same rect from two different threads at the same time. Since I load images in this call, it causes the view to load very slow.

2011-10-18 14:07:18.802 APP[12436:19003] drawRect:{{0, 400}, {368, 400}} (view:<TiledScrollColumn: 0x91bc880; frame = (0 1600; 368 5400); userInteractionEnabled = NO; layer = <CATiledLayer: 0x919c1b0>>)
2011-10-18 14:07:18.805 APP[12436:1b103] drawRect:{{0, 400}, {368, 400}} (view:<TiledScrollColumn: 0x91bc880; frame = (0 1600; 368 5400); userInteractionEnabled = NO; layer = <CATiledLayer: 0x919c1b0>>)

Has anyone an idea what could cause that or what I could do to fix that? I’m not doing special stuff with the view, it’s based on the photoscroller example.

Bastian

  • 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-28T00:47:08+00:00Added an answer on May 28, 2026 at 12:47 am

    I found a workaround. Create a serial (only one operation at at time) dispatch queue and perform all your drawing inside it, then cache the result.

    I’ve attached the code I’m using, note I’m using a subclass of CATiledLayer, rather than drawing it through a delegate or other techniques.

    I’m also creating an indefinite tile cache, which may cause memory issues depending on your situation. You may need to manage the number of tiles in the cache, deleting old ones as new ones are added. The cache should also be cleared when a low memory warning is received. If anyone adds these improvements, please feel free to edit my answer to include it.

    - (id)init
    {
      if (!(self = [super init]))
        return nil;
    
      tileCache = [[NSMutableDictionary alloc] init];
    
      return self;
    }
    
    - (void)drawInContext:(CGContextRef)layerContext
    {
      // CATiledLayer has a bug, where it spawns multiple threads for drawing, and then tries to draw the same tile multiple times simultaniously on separate threads
      // so we create our own serial background queue, and do dispatch_async on it. This will cache each draw operation, so multiple calls on one tile are efficient
      static dispatch_queue_t drawQueue = NULL;
      static dispatch_once_t onceToken;
      dispatch_once(&onceToken, ^{
          drawQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
      });
    
      dispatch_sync(drawQueue, ^{
    
        // no map ways? draw nothing
        if (!self.mapWays)
          return;
    
        // load from cache?
        CGRect tileRect = CGContextGetClipBoundingBox(layerContext);
        NSString *tileCacheKey = [NSString stringWithFormat:@"%f%f%f%f", tileRect.origin.x, tileRect.origin.y, tileRect.size.width, tileRect.size.height];
        __block UIImage *tileImage;
        dispatch_sync(dispatch_get_main_queue(), ^{
          tileImage = [tileCache objectForKey:tileCacheKey];
        });
        if (tileImage) {
          CGContextDrawImage(layerContext, tileRect, tileImage.CGImage);
          return;
        }
    
        // prepare to draw the tile image
        UIGraphicsBeginImageContextWithOptions(tileRect.size, YES, 0);
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        // filp coords
        CGContextTranslateCTM(context, 0, tileRect.size.height);
        CGContextScaleCTM(context, 1.0, -1.0);
    
    
        /*** do actual drawing here ***/
    
    
        // store tile in cache
        tileImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        dispatch_sync(dispatch_get_main_queue(), ^{
          [tileCache setObject:tileImage forKey:tileCacheKey];
        });
    
        // draw the tile
        CGContextDrawImage(layerContext, tileRect, tileImage.CGImage);
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in some JavaScript that I am writing where the Switch statement
I have problem with fancybox. I want to write a function that will run
I have a CATiledLayer inside a UIScrollView and all is working fine. Now I
I have a CATiledLayer that is used to display a PDF page (this CATiledLayer
I have problem with Activities navigation, searching works good. Activities hierarchy looks like that:
I have problem with passing variables through views. But, first some code // i
I have problem running my app on Android 2.3 (Gingerbread). The app has a
I have problem in C#. I have a list box and a class called
I have problem with resized editText (I made him smaller, actually), he has 40dip
I have a Problem with a UIScrollView CATiledLAyer stucture. What I'm doing is showing

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.