have you tried turning it on and off again: libxpc

Tuesday, December 20, 2011

There was a weird hang we were seeing in Float. It would occur anytime a text field became the first responder. The issue could be reproduced with our development build as well as the live app store build. The hang had the following frames at the top of the callstack for the main thread: Google didn't return useful results for some the various _xpc* function names. Although the libxpc keyword seemed to be associated with "hang." I went and grabbed another 4S. Fortunately, the issue did not repro. From what I could tell libxpc is related to remote debugging. However, it never shutdown properly and was left running to break as it pleased. After a quick reboot of the device we were back to normal. Seeing as Google was pretty sparse on this issue I hope this will save others some time.

good tools

Sunday, February 13, 2011

I recently moved to doing BlackBerry development at work which required me to go through setting up a new environment. I had successfully setup iPhone and Android environments by simply following the directions on their web sites. Not surprisingly, Apple has the easiest development environment to get setup. Google had a few more steps but made up for it with good documentation. To get started on Blackberry development I installed a bunch of software from this page: Eclipse for Blackberry Development, Blackberry Java Development Environment (JDE), Torch Simulator, MDS Simulator. Ok good to go. I was able to build our product and run it on a simulator. Next I started playing around with the app. Setting breakpoints and getting an idea of how things were plugged together. I wanted to try out the voice search feature and thought the simulator would use the PC mic but it was not working. I figured it should be easy to load the app on a device and eliminate the simulator as the cause of the problem. The JDE comes with a tool called JavaLoader for placing builds on the device. I plugged the device into the computer and ran the tool. It dumped info to the terminal of what it was doing and left me with an error message: HRESULT: 80040154. With a quick search I found that error code meant the a COM class could not be instantiated. I figured I probably did not install the software which allowed for communication with the device over USB. But what was it? With COM to create an object you pass in a GUID and bam you have yourself an instance of some class (an oversimplification but good enough for this). Underneath the hood the program is really digging through the Windows registry looking for that GUID. If I could find that GUID I could easily find what I was missing with a quick web search. To find the GUID I fired up procmon and reran the JavaLoader program. Procmon is magic in a box. It shows all the different events taking place with the file system and registry for the whole system or a particular process. It helped me find the GUID in question as seen in the picture below:
I searched for BA3D0120-E617-4F66-ADCA-585CC2FB86DB and found a stackoverflow entry indicating that Blackberry Desktop Manager needed to be installed. Once I installed it everything work as expected. Lesson today: Good tools make life better.

objective-c blocks

Monday, February 7, 2011

Objective-C features anonymous functions via what they call blocks. I was a little fuzzy on the memory management rules of blocks at first. The basic rules are: the block structure is stack allocated and blocks retain Objective-C objects they reference until the block is deallocated. In order to keep the block around beyond the lifetime of a stack frame the block must be copied to the heap. All of the objects directly referenced within the block will be retained. When the block is released those objects will also be released. Keep in mind the retained objects may have weak references to other objects that may end up getting freed before one would expect. For example, an objects delegate is typically not retained. A simple mistake would be to perform an asynchronous action which causes a view to update but has the possibility of the delegate being released before that action has the opportunity to complete. With the Flickr app I spoke of previously I messed up on both rules. First, my block referenced tableView whose delegate was the view controller. With the code below it will likely fail if the user backs away before all the thumbnails finish loading.
Once the user backs away from the table’s view controller it will be released. It is possible the queue will still be downloading thumbnails. Once a thumbnail is downloaded the block passed to thumbnailWithBlock will be called and attempt to update the table only to have the program crash. Instead of sending the reload message to tableView I send the reload message to self.tableView. In this case self is the view controller for the table view and since it is now reference in the block it will be retained for later use. After using Grand Central Dispatch (GCD) to perform the image fetching I wanted to see how it could be done with NSURLConnection. NSURLConnection handles all of the networking on a separate thread. It notifies the UI thread via various delegate methods of the download progress. I simply changed the thumbnailWithBlock on the Photo object to use NSURLConnection and store a pointer to the block object for use later. When the download finished I called the block with the downloaded data but the program crashed. The reason was I had failed to copy the block to the heap and was getting the EXC_BAD_ACCESS error. The fix was to send a copy message to the block and be sure to release it after using it with the downloaded data. Once I figured that all out I wondered how GCD handled blocks. It must copy them or else it would be getting EXC_BAD_ACCESS errors. Me being curious I went and looked and sure enough they copy the blocks before using them.

phantom mapkit polylines

Wednesday, February 2, 2011

I was toying around with MapKit today and I am pretty sure I found a bug. MapKit renders an extra line along the equator if a polyline's point has a latitude of zero or an extra line along the prime meridian if its longitude is zero AND if the line width is less than or equal to 1.0. The code snippet to reproduce the issue can be found here: https://gist.github.com/808845. And also a screenshot of the result:

the great uitableview race

Monday, January 31, 2011

For the iTunes U course on iOS programming I followed along with the homework assignments. The last assignment was a Flickr app that shows photos at popular geotagged locations. I had an issue with UITableViewCell reuse and background threads populating the thumbnail image that I thought was worth sharing. On iOS in order to improve performance some of the different libraries like UIKit and MapKit have the ability to reuse UI elements once they are no longer on screen. When reuse occurs it is up to the developer to provide new data for the UI element. My problem was that two or more asynchronous operations could change the same table cell. One solution would be to stop reusing table cells but that is not ideal. As long as I can identify which image should be shown in the cell at a given time I can make sure the correct asynchronous operation updates the cell. Since UITableViewCell derives from UIView it has the tag property which is a NSInteger. The UITableView represents an array of data from Flickr. Before making the asynchronous call I set the cell’s tag to the index in that array it currently represents. Then in the callback function I only update the cell if its tag matches the index for which the asynchronous call was made. Without this change in place it is possible to scroll through the list rapidly and see the thumbnail change two or three times for a cell while the remaining thumbnail downloads finish. But the last update could be the wrong thumbnail. The code itself is simple and can be found here: https://gist.github.com/803766.

silly apple ui

Monday, January 24, 2011

I have been working my way through the Stanford iOS programming course. It’s been my biggest exposure to the Apple developer ecosystem. So far I have encountered three user interface components in the tooling that I trip me up. The first is Interface Builder (IB). This tool is separate from the XCode IDE. I typically forget to save changes. In my mind XCode and IB are one and so I expect my changes to be saved when I build. I usually end up with a blank screen and then I remember: save in IB! In XCode 4 IB is supposed to be integrated so hopefully this issue is fixed. On the code side of things all the UI pointers are nil. In Objective C it is perfectly valid to send messages to those nil objects. Personally, I would like to fail fast and have the program crash as I think that would help me find the root cause quicker. Second, when opening older projects I often get the “Base SDK is missing” error. It’s easy to change in the project’s build settings but after the change it seems you must reload the project in XCode. It wasn’t entirely obvious at first but restarting an application usually fixes everything regardless of the platform. Finally, I wanted to see how my custom drawRect: code was visually different on the retina display versus the old display. I checked out an older device from work and took it too my office and tried to provision only to receive this error message:
Only one developer gets to register a device I figured. I searched the internet a bit and finally decided I would just provision the device as a tester’s device. While I was looking for the page to do that I found my device list had two devices listed. That was odd because I only expected to see my iPod listed. I looked at the second device and sure enough it had the same ID number as the device I had checked out. The dialog meant to add devices didn’t tell me it had done this. It only displayed an error message asking for another ID number. Overall the tooling is pretty good and it does not get in the way that often.

facebook ads

Monday, January 17, 2011

If Facebook ads are any indicator of the health of the economy then it must be great. For the past 2-3 months I have noticed an increase in the number of job ads. I think the cause might be one or a combination of the following:
  • More employers are using Facebook to advertise open positions which could mean the economy is doing better. Yay!
  • I switched jobs from a Visual Studio SDET to Bing Mobile SDE back in October. The “developer” label probably draws more employer attention than the “tester” label.
  • The Microsoft keyword in my profile certainly helps. It’s like going to a big name school. Society assumes it must be good. In the big scheme of things it’s pretty silly to base potential success off of that attribute alone.
Here are some of the job ads I have seen so far:It’s not uncommon for 2 or 3 of these to show up on any given Facebook page. The Marchex ad always catches my eye. Their tag line reads: “Tired of Reorgs.” Which probably catches the attention of most Microsoft employees. I think ads on Facebook are going to start to look more and more like this though. They will continue to get more personal in nature. I know I click on more Facebook ads than Google ads. When something is so relavent it sparks my curiosity. I don’t know that Facebook will take away Google’s AdWord revenue but I think they are in a pretty good position to compete for AdSense revenue. IMDB.com also advertises positions on Facebook. They didn’t take the “reorg” approach but went with the commute. The 520 bridge which connects Seattle to Microsoft can get backed up. Personally, I am not “tired of the bridge” as their ad said since I don’t live in Seattle. Their ad was clever but not clever enough to take my address into account. Finally, the last ad that caught my eye had the tag line: “Stressed At Microsoft?” The ad was for counseling services at eastsidecounseling.org. Between the competitor’s job ads and counseling ads a cynic might say Microsoft isn’t the place to work. I wonder what kind of targeted ads I would see if I worked at Google, Amazon, Facebook or Apple? For Amazon I am guessing “Tired of the Pager” would make a pretty catchy tag line. I am sure the others have quirks their competitors use to attract talent but I don’t know enough about those companies to venture a guess.