daltoniam / Skeets

Fetch, cache, and display images via HTTP in Swift.
Apache License 2.0
191 stars 21 forks source link

fatal error: can not decrement startIndex #19

Closed darer closed 9 years ago

darer commented 9 years ago

Now I get an error on first launch of the app (after install). It's in the ImageManager.swift file in:

    private func hash(u: String) -> String {
    var url = u
    let len = count(url)-1
    if url[advance(url.startIndex,len)] == "/" { 
        url = url[url.startIndex..<advance(url.startIndex,len)]
    }
    var hash: UInt32 = 0
    for codeUnit in url.utf8 {
        hash += UInt32(codeUnit)
        hash ^= (hash >> 6)
    }

    hash += (hash << 3)
    hash ^= (hash >> 11)
    hash += (hash << 15)

    return "\(hash)"
}

I get "fatal error: can not decrement startIndex" on the forth line. This doesn't happen every time. I need to reset the simulator and install again a few times until I can reproduce this. But once I get this error, I can't launch the app at all and I need to reinstall again. Any ideas what could cause this?

darer commented 9 years ago

After I got this error a few times I checked the other issues and I found this updated hash function (above). I tested with it, and it's still the same. So I guess it doesn't matter if I use the old function or this one.

darer commented 9 years ago

Never mind, the problem was in my code. It gives that error only when it tries to fetch an image before my db sync is complete. I reinstalled the app like 20 times now and it works fine. Closing the issue.