Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Bug Cellphones Programming

Bizarre Droid Auto-Focus Bug Revealed 275

itwbennett writes "Pity the poor engineer who had to find this one. One of the more interesting of the handful of bugs that have appeared since the launch of Verizon's Droid smartphone has to do with the on-board camera's auto-focus. Apparently it just didn't work. And then suddenly it did. Naturally, this off-again, on-again made the theories fly. But the real reason for the bug was revealed in a comment on an Engadget post by someone claiming to be Google engineer Dan Morrill: 'There's a rounding-error bug in the camera driver's autofocus routine (which uses a timestamp) that causes autofocus to behave poorly on a 24.5-day cycle,' said Morrill. 'That is, it'll work for 24.5 days, then have poor performance for 24.5 days, then work again. The 17th is the start of a new 'works correctly' cycle, so the devices will be fine for a while. A permanent fix is in the works.'"
This discussion has been archived. No new comments can be posted.

Bizarre Droid Auto-Focus Bug Revealed

Comments Filter:
  • by eldavojohn ( 898314 ) * <eldavojohn@gm a i l . com> on Wednesday November 18, 2009 @02:59PM (#30147842) Journal
    It's all over the comments on the engadget page but since 2^31 milliseconds is about 24.5 days, it's highly probably we're dealing with a very classic not so funny sign extension bug here [wikipedia.org]. So if I may presume the real problem, it's that autofocusing depends on catching timestamps from the system to know how long it's been since the last sampling in order to adjust the lens and check for accuracy. It's casting this to a signed 32 bit variable which means that during the 24.5 days it is miscast to a negative number, thus breaking the algorithm when it measures time deltas and causing it to mis focus before snapping the picture.

    The patch is simple, make that signed int something like an unsigned long or truncate it properly. Hopefully we're not waiting long.
    • by Singularity42 ( 1658297 ) * on Wednesday November 18, 2009 @03:09PM (#30147956)

      I've been waiting a long long time for standardization of integer types.

    • by Whalou ( 721698 ) on Wednesday November 18, 2009 @03:14PM (#30148026)

      Hopefully we're not waiting long.

      We're waiting unsigned long.

    • by sootman ( 158191 )

      I was just about to post, asking "Why does the autofocus need to know what time it is?" Thanks for the info.

    • by Anonymous Coward on Wednesday November 18, 2009 @03:25PM (#30148134)

      Waiting long? Hopefully we're not waiting double!

    • by msauve ( 701917 ) on Wednesday November 18, 2009 @03:28PM (#30148160)
      Probably not measuring the times per sampling, but measuring the time the focus mechanism is moving. To keep costs down, I suspect the mechanism has no feedback mechanism, so to focus you move one way for a set amount of time (guaranteed to hit a mechanical stop). Then the software might keep track of focus position by how long it's driven the lens in one direction or the other starting at that known position (oops, I moved "out" 100 ms, but overshoot, so now I'll move "in" 50 ms). Or it might be that the bug makes it so the lens never gets properly reset to it's starting position.
    • What I don't get is why a time stamp is needed to focus. Most cameras don't seem to need to know what time it is in order to do that.

      • by BitZtream ( 692029 ) on Wednesday November 18, 2009 @03:47PM (#30148396)

        Most cameras do, they just don't use a RTC value to do so.

        You don't want it continually focusing, you want it to focus then wait a bit otherwise it'll bounce all over the place. You check the distance, wait a moment, and check again, is it close to the same? If so use that as your focal length, other wise you'll probably end up never in focus cause you'll be using all the various raw values given to you by the sensor. This is likely input averaging to get a smooth value and throw out bad samples.

        Take a look at the raw input values provided by most game controllers, try to hold an analog stick in one spot and not get jitter in the raw values, unless the device itself is averaging you won't got a solid result. Plug a xbox controller into your PC and use the Windows control panel (if you're using windows, never plugged a joystick into a unix box myself) to see how jumpy it is.

        A sensor measuring the environment outside, in someones hand is going to bounce around like a mad man, so it has to be smoothed out somehow.

    • Sounds like something to add to the jargon file [catb.org] :)

    • Seems like having a system timer trigger the auto focus update event would be a far better method of dealing with it rather than polling to check if its time to update again in some sort of loop.

      Android DOES have timers usable by drivers doesn't it? Requiring drivers to poll would be very shitty indeed, especially on devices with lower CPU power..

    • by AaronW ( 33736 )

      When I first read about this that was the first thing that came into my mind as well. Elsewhere I found another post where a permanent fix should be available on December 11th, which is the day that the bug will re-appear.

    • by noidentity ( 188756 ) on Wednesday November 18, 2009 @04:00PM (#30148578)

      it's highly probably we're dealing with a very classic not so funny sign extension bug here [...] It's casting this to a signed 32 bit variable which means that during the 24.5 days it is miscast to a negative number

      This involves truncation, not sign-extension, actually. Sign-extension occurs when widening a value, not narrowing it. A value outside the range representable by a two's complement 32-bit integer is being cast to one, and apparently this platform simply truncates to 32 bits and treats the highest bit as having the value -2^31, rather than 2^31 as it had in the input value. This isn't the only way to handle such a situation; common alternatives are raising an exception or saturating (i.e. anything >= 2^31 converts to 2^31-1, and anything less than -2^31 converts to -2^31).

    • The engadget poster mentions a rounding bug, not a sign-extension bug. (and for it to be a sign-extension bug, they would need to be extending from 32-bit timestamps to 64-bit timestamps).

      That doesn't mean it's not the 2^31 ms ~= 24.5 days. It could be that the platform "rounds toward zero", and the developers anticipated that to mean "round down" in the context of numbers that are always positive...and when the numbers become negative, it rounds up instead, and screws them.

      The best theory I've heard so f

    • Well, if it's written in Java like the rest of Android, it could be a bit more work. T'aint no "unsigned" in Java.
    • Comment removed (Score:4, Insightful)

      by account_deleted ( 4530225 ) on Wednesday November 18, 2009 @04:47PM (#30149142)
      Comment removed based on user account deletion
    • Hmmm, did the auto-focus programmer used to work on the Patriot anti-missile system?
         

  • Just curious.....

  • Auto-Focus (Score:5, Funny)

    by kellyb9 ( 954229 ) on Wednesday November 18, 2009 @03:02PM (#30147870)
    ... Droid doesn't
  • by EdIII ( 1114411 ) * on Wednesday November 18, 2009 @03:05PM (#30147894)

    Spring Break, the biggest part of it, occurs within a working cycle.

    • by spruce ( 454842 )

      Right, like the camera is going to be the most common cause of out of focus pictures during spring break.

      "OMG EVERYBODY LISTEN - DO 6 JELLO SHOTS WITH ME, THEN SAY CHEEZ. *burp*, *snap* AWW, THE CAMERA DIN'T WORK GUD"

  • Alleged... (Score:5, Funny)

    by Anonymous Coward on Wednesday November 18, 2009 @03:08PM (#30147938)

    by someone claiming to be Google engineer Dan Morrill

    Yeah, it could also be one of those lame Dan Morrill impersonators who solve perplexing engineering/programming issues, then post the solution under his name. MAN that's annoying..

    • Re:Alleged... (Score:4, Interesting)

      by Artraze ( 600366 ) on Wednesday November 18, 2009 @04:33PM (#30148970)

      You kid, and I can appreciate the humor, but it was stated that way as a matter of journalistic integrity. Rather than claiming the the true Dan Morrill posted this (which they have no proof of) they stated what they did know: the person that posted this says he's Dan Morrill. That way if it turns out that Dan Morrill didn't actually post it, they've not put word into someone's mouth, as it were, and only need to release an update along the lines of "Bug discoverer really someone else".

      It's sad that we've become so used to the modern media's 'report what you think happened and maybe correct yourself later if you're called on it' style that phrases like this are actually worthy of comment, humorous or otherwise....

  • by OzPeter ( 195038 ) on Wednesday November 18, 2009 @03:10PM (#30147980)
    This is definitely NOT the Droid you are looking for
  • by Anonymous Coward on Wednesday November 18, 2009 @03:13PM (#30148020)

    Just buy two with opposing date stamps.

  • Time-releated bugs (Score:5, Interesting)

    by Iphtashu Fitz ( 263795 ) on Wednesday November 18, 2009 @03:16PM (#30148054)

    15+ years ago I had to debug some code in a report printing app for OS/2 (remember that OS?). The bug would cause the app to crash when a report was printed out. But the bug would only happen on certain days. Certain days in September. Only on Wednesdays in September. Only when it was a Wednesday in September after the 9th.

    The bug? The original programmer had tried to optimize memory usage as much as possible and was off by a count of one. With "September" being the longest month spelled out, "Wednesday" the longest day spelled out, and a 2 digit date, the header that the program put together to send to the printer would overflow its buffer by one character.

    • by qoncept ( 599709 ) on Wednesday November 18, 2009 @03:43PM (#30148326) Homepage
      I got a "bug report" that our Oracle Forms app would give an undefined error message after you "type in a first name, push tab twice, and click save 17 times." I didn't debug it, but I did offer a workaround.

      I also had a bug report for when you tried to add a prerequisite that didn't exist to a training task (the system tracked flight Air Force crew training and experience), an error would pop up that said "All this time and it still doesn't work..." In that case, apparently debugging was as far as anyone ever got.
      • by amicusNYCL ( 1538833 ) on Wednesday November 18, 2009 @04:25PM (#30148892)

        I also had a bug report for when you tried to add a prerequisite that didn't exist to a training task (the system tracked flight Air Force crew training and experience), an error would pop up that said "All this time and it still doesn't work..." In that case, apparently debugging was as far as anyone ever got.

        Please tell me these aren't the same developers who wrote the Air Force's current LMS. If so, that would explain a lot. I actually submitted a bug report to the Air Force once about their LMS complete with the section of code (Javascript) that was incorrect, an explanation about why it was incorrect, the corrected code, and an explanation about why the changes fixed the issue. They responded and said that they were "reluctant" to agree with me, and never made the changes.

        Oh yeah, the "bug fix" was the difference between this:

        score = parseInt(score);

        and this:

        score = parseInt(score, 10);
        if (isNaN(score)) score = 0;

    • There was a wonderful bug in ubuntu where it wouldn't print on tuesdays. It would generate a postscript file, which includes the date, but a faulty entry for file-type detection caused postscript on tuesday to be interpreted as some kind of erlang file... which obviously didn't print very well :)

      http://bugs.launchpad.net/ubuntu/+source/file/+bug/248619 [launchpad.net]

  • by wiredog ( 43288 ) on Wednesday November 18, 2009 @03:16PM (#30148060) Journal

    that caused Windows 95 to require a reboot in about the same timeframe.

  • Wow (Score:4, Funny)

    by QuoteMstr ( 55051 ) <dan.colascione@gmail.com> on Wednesday November 18, 2009 @03:17PM (#30148066)

    Considering that a lunar cycle is 29.5 days long, we've actually found a bug that depends (approximately) on the phase of the moon!

  • "'There's a rounding-error bug in the camera driver's autofocus routine (which uses a timestamp) that causes autofocus to behave poorly on a 24.5-day cycle,' said Morrill."

    Cool! The device will later be fixed to properly behave poorly only every 24.45 days!

  • I can verify this- I got a Droid on launch day, and one thing that drove me nuts was how long it took a barcode scanning app to focus and accquire the barcode... i just tried it again after writing off that ability, and sure enough, the time to focus is much, much shorter now.
  • "Tasks accomplished: fixed timestamp rounding error in autofocus subroutine"

    vs.

    "Tasks accomplished: designed/implemented autofocus subroutine"

  • by acidblood ( 247709 ) <decio.decpp@net> on Wednesday November 18, 2009 @03:42PM (#30148314) Homepage

    Since we're talking about phone bugs, here's one I had to fight with for a while...

    Lots of users are having problems with the GPS functionality on the iPhone 3G/3GS (see e.g. here [apple.com]). No apparent pattern there, but in Brazil, lots of users from one specific carrier were having GPS problems, and the beginning of these problems coincided with the start of Daylight Savings Time in Brazil. My iPhone, as well as my girlfriend's, are with this carrier and were experiencing the problem. Those with unlocked phones report trying other carriers' SIM cards and had GPS working again, but once you popped back the problematic carrier's SIM card, the GPS was dead again.

    This nearly drove me nuts as I paid an obscene amount of money for the TomTom app and couldn't get it to work, so keeping up with the engineer spirit, I tried to debug the problem myself. I observed an interesting fact: there's a Clock app on the iPhone with a World Clock pane, and if I added a clock from any time zone, including my own, it was off by one hour. However the iPhone's main clock, shown on the top of the screen, was showing the right time. Eventually I discovered that if I restored my phone as a brand new phone (not restoring from backup) the GPS would work fine and world clocks would be fine... until you reboot the phone. After rebooting, the GPS is gone again and the world clock is off by one hour again.

    Now you might ask what the time has to do with GPS. A lot, it turns out. GPS works by triangulating your distance from the satellites in the GPS constellation, which depends on knowing the exact position of the satellites. Since their orbits are corrected every so often, you must rely on so-called ephemeris data from each satellite, which is the required information to compute fairly exact orbits, and is updated fairly often (Wikipedia says GPS receivers should update ephemeris data every 4 hours). Originally this data is broadcast by the satellites themselves in their navigation message, at an awfully slow rate of 50 bits/s. You read it right, bits, not bytes or KB or MB, that's bits. As the navigation message is 1500 bits long, it takes at least 30 seconds to download it, which is about the time most standalone GPS receivers take to get a fix from a cold start (i.e. with stale ephemeris data). To work around this delay, most phones with GPS use the assisted-GPS variety, which downloads ephemeris data from a faster channel such as the cellular network. My theory is that some WTF-worthy excuse for an engineer at the carrier decided that, rather than doing time zone updates the right way, by updating configuration files to point to the new time zone, he'd just rather adjust the clock forward by one hour. The GPS chipset probably works with time zone neutral clocks so it asks for (say) UTC time and gets it off by one hour, and then computes the satellite orbits as though it were one hour later than it actually is. Obviously this means the triangulation computations go horribly wrong and rather than reporting something absurd, the chipset just pretends it couldn't get a fix.

    It took a lot of complaining from a lot of people (to the carrier and to the government agencies responsible for telecommunications), but the carrier finally fixed the problem. However, it was a nightmare trying to deal with clueless customer support representatives who didn't try in the least to help (and probably were thinking all along `what does this wacko think GPS has to do with DST?'), just blindly suggesting that we restore the phone, or even try to uninstall the built-in Maps app, or blaming it on Apple and saying they weren't responsible -- and never mind that unlocked phones with SIM cards from other carriers worked fine, and that the iPhone support situation is unique in Brazil as Apple outsourced support to the carriers themselves. In the end, the customer support WTFs would be worth another post of its own, at least twice the size of this one.

    But

    • Re: (Score:3, Insightful)

      by Anonymous Coward

      GPS works by trilaturation [wikipedia.org], not triangulation... just sayin'

  • by cryfreedomlove ( 929828 ) on Wednesday November 18, 2009 @03:50PM (#30148430)
    It is gratifying for Google to be so open about the fact that it is a bug, the details of the bug, and a promise to fix it. Most consumer electronics companies are much more cagey about this sort of thing. I suspect Google will win some important trust because they are treating their customers like adults.
    • by Ironica ( 124657 ) <pixelNO@SPAMboondock.org> on Wednesday November 18, 2009 @04:33PM (#30148978) Journal

      It is gratifying for Google to be so open about the fact that it is a bug, the details of the bug, and a promise to fix it. Most consumer electronics companies are much more cagey about this sort of thing. I suspect Google will win some important trust because they are treating their customers like adults.

      I realize the post was made by a Google engineer, but, wouldn't a bug in "the camera driver's autofocus routine" be on Motorola's end, not Google's? I'm sure they were working together on it, but aren't drivers usually written by the hardware vendor?

  • ... but the iPhone does.

  • by Gavin Scott ( 15916 ) on Wednesday November 18, 2009 @04:12PM (#30148738)

    After about 42 years my auto-focus suddenly stopped working as well.

    You think if I live to 84 or so it will suddenly get better again?

    I sure hope there's a patch...

    G.

  • Half the focus group users did not want in-focus photos taken of them for a few days each month. Some idiot male programmer clearly mistyped the constant.
  • ...like a bad motivator.

  • Bigger bugs afoot... (Score:5, Interesting)

    by jddj ( 1085169 ) on Wednesday November 18, 2009 @04:19PM (#30148826) Journal

    Honestly, autofocus on the just-so-so camera is the last of my worries:

    • Can't sync with Outlook (the phone doesn't have on-device encryption that would satisfy Exchange policies). Only calendar works, not contacts or email.
    • Can't hands-free voice dial (have to touch the phone to unlock it, touch to turn on voice dial, speak your choice, touch the choice from the menu of likely suspected contacts).
    • Locked phone's touch-screen comes on in pocket when answering with a headset, causing much mute/disconnect/speakerphone hilarity.
    • Turn-by-turn navigation is way off, literally by miles. Wrong 4 of 4 tries so far (in metro Atlanta and DC).
    • Immature bluetooth won't support HCI (portable bluetooth keyboards).
    • Rotating the phone after checking email checkboxes unchecks everything
    • Can't order contact list by last name (fixed in first name order)
    • Can't charge it with ANYTHING but the included AC adaptor (over-draws USB power from my old USB car and wall chargers)

    Really, fix the camera sometime down the line. But make the phone dial hands-free. Make email work. Make the navigation something other than worthless. Make "lock the screen" really lock the screen.

    Someone at Google should use one of their own phones for a while and see how (s)he likes it.

    It's a wonderfully powerful platform, but clearly not as well-thought-out or fluid to work as iPhone/iPod Touch

    • by DeadCatX2 ( 950953 ) on Wednesday November 18, 2009 @04:35PM (#30149014) Journal

      Exchange works great for me. So does navigation. I had no problem charging my phone with my netbook's USB port. I did, however, notice that changing the orientation can cause not-yet-applied settings to be forgotten (happened to me while setting up Exchange).

      I don't have any Bluetooth stuff so I can't comment on Bluetooth support, but I imagine it will improve. Bluetooth seems like a very temperamental protocol. That said, hands-free Bluetooth voice dialing is actually a showstopper for a lot of important business types, so that should get fixed right away.

      If you don't like the native Contacts application, I'm sure you can find some others. Personally, I use the Favorites tab of the Contacts widget, and that handles 95% of the times I want to make a phone call in two clicks.

      Finally...Motorola made the phone, not Google.

    • by Mike Buddha ( 10734 ) on Wednesday November 18, 2009 @04:36PM (#30149034)

      • Can't sync with Outlook (the phone doesn't have on-device encryption that would satisfy Exchange policies).

      They should've just made it to lie about its policy enforcement to Exchange server like the iPhone did. That way it'd be banned from my corporate network like my iPhone was. Thanks Steve, you're such a smart guy.

      • Re: (Score:3, Informative)

        by pwagland ( 472537 )

        • Can't sync with Outlook (the phone doesn't have on-device encryption that would satisfy Exchange policies).

        They should've just made it to lie about its policy enforcement to Exchange server like the iPhone did. That way it'd be banned from my corporate network like my iPhone was. Thanks Steve, you're such a smart guy.

        Just as an aside, that bug is now fixed [goip.com]. To cut the story short, the 3GS does support it properly, earlier models do not, and iPhone 3.1 properly reports this to the server now.

    • Re: (Score:3, Interesting)

      by hey! ( 33014 )

      What I've seen is that some chargers power any USB powered equipment (including those on my PCs and laptops) and other wall and car chargers only power *some* USB powered equipment. I'm guessing what's going on here is that some equipment (usually expensive thingies) refuse to run off an unregulated supply. I've seen the same thing happen with a battery powered USB charger I whipped up. Some equipment won't recognize it until the batteries are drained a bit. That includes my new droid phone.

      With respec

  • by Animats ( 122034 ) on Wednesday November 18, 2009 @05:17PM (#30149512) Homepage

    The initial release of 4.3BSD had a bug like that. It wouldn't interoperate with implementations that chose TCP sequence numbers in the upper half of the 32-bit address space. BSD itself didn't do this until it had been up for 2^31 seconds, so it got through testing. Other implementations cycled faster. We were losing network connections for two hours out of every four.

    It took a 1-line fix, after three days of looking at the generated machine code to figure out exactly how the sequence number arithmetic worked. Too many casts in the source.

    • Re: (Score:3, Interesting)

      by TwinkieStix ( 571736 )

      (2^31) seconds = 68.0511039 years of uptime before the bug manifests? So this wasn't much of a problem for BSD?

Keep up the good work! But please don't ask me to help.

Working...