Featured Posts

How to background load and cache UIImageViews images It's often the case that the apps I am working on are required to download quite a couple, or even a few dozen, images and display them in a UIImageView. In looking online I found a few different methods...

Readmore

It sure does snow in Kansas! This week I am visiting my Grandmother in Kansas. Monday night I arrived at the farm just as the first snow was falling, and by Tuesday morning I couldn't have left if I wanted to. Here are some pictures...

Readmore

*Warning* Do not install software included in Panasonic... Background A while back I purchased a Panasonic camera that can not only take pictures, but also record video. I chose the camera because of this combination, in combination with it's optical zoom. Now,...

Readmore

UPS continues tradition of poor service Warning, rant ahead! I don't like posting such, but UPS is making my life miserable often enough that I feel I have to. Anyway, I purchased a product recently which the company shipped via UPS with...

Readmore

Suggestions to correct iTunes / iPhone music sync Recently I had a coworker who upgraded his iPhone to 3.0 find that he could no longer sync that iPhone with his iTunes music library on a Windows computer. It would, however, sync just fine on a Mac OS...

Readmore

  • Prev
  • Next

CAContextInvalidLayer and setFence:count

Posted on : 07-06-2009 | By : Lane Roathe | In : Development, featured, iPhone

Tags: , ,

0

So there I was, up for nearly a day straight and have figured out the certificate issue that was preventing my program from running on my iPhone after upgrading to SDK 3.0 beta 5.

On the device I was getting this error: CAContextInvalidLayer - CALayer already attached to a context while on the simulator I was getting this error: setFence:count: called more than once per transaction. Cryptic messages that googling for solutions found no answers to.

After many hours of investigation and trial and error, I checked out older revisions of my code base (gotta love svn, or any revision control system for that matter!) until I arrived at a build that installed and ran on the device. From there I started doing file by file compares with the next version (which didn’t install) looking for anything that might be the cause.

Finding nothing obvious, I started implementing each change one by one. The difference between the revisions were minor and few in count (as any good checkin should be) so this didn’t take long… and I arrived at a solution!

My application was using several layers to create visual effects. At one point I made a “change that will make no difference”, and so minor I kept ignoring it in my code reviews! However, this code was the cause of all of my issues… but only long after the actual code had been run.

The problem came down to how I created my layers. I had started out very basic, but then thought it would be better to make a copy of the first layer so I could inherit more of it’s properties. However, this code:

targetLayer = [[CALayer layer] initWithLayer:self.layer];

copied too much information and when I later tried to work with the layers I ran into the “already attached” problem. The correct way to create layers for my program (and what I started out with) is:
targetLayer = [CALayer layer];

Reverting that one change in my latest code base let me get back to making progress. Hopefully documenting my error here will save someone else a few minutes or hours if they run into the same issue.