Crash on keyForImage
Closed this issue · 5 comments
Hi There!
I've been getting a EXC_BAD_ACCESS crash on line 708 of YapImageManager.swift specifically on:
key += String(format: "(URLString ?? "")%0.5f%0.5f", size?.width ?? 0.0, size?.height ?? 0.0)
If URLString contains a value and it does not contain any placeholders for the arguments passed (width and height) it crashes. If I just pass URLString or remove URLString and leave the rest of the string formatting, then it works fine.
Not sure if you had this happen before.
(lldb) po String(format: "\("<na>")_%0.5f_%0.5f", size?.width ?? 0.0, size?.height ?? 0.0)
"<na>_304.00000_375.00000"
(lldb) po String(format: "_%0.5f_%0.5f", size?.width ?? 0.0, size?.height ?? 0.0)
"_304.00000_375.00000"
(lldb) po String(format: "\(URLString ?? "<na>")")
"https://static.fragds.com/legacy-contentassets/image/Trivesta/9720_1476212759000_video-still_7339_Trivesta(null)re-Launch nglish.jpg"
(lldb) po String(format: "\(URLString ?? "<na>")_%0.5f_%0.5f", size?.width ?? 0.0, size?.height ?? 0.0)
error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x4073000000000000).
The process has been returned to the state before expression evaluation.
po URLString
▿ Optional<String>
- some : "https://static.fragds.com/legacy-contentassets/image/Trivesta/9720_1476212759000_video-still_7339_Trivesta%252520Pre-Launch%252520English.jpg"
Oh, I think maybe the encoding of the URL (%252520) is causing the issue?
Hi,
That makes sense! Good catch. The url should not be part of the format string. Something like this should work better:
key += String(format: "%@_%0.5f_%0.5f", URLString ?? "<na>", size?.width ?? 0.0, size?.height ?? 0.0)
Let me know if you want to create a PR or if you prefer for me to fix and push a release.
Thanks,
Trevor.
Is it ok to have the key be URL_0.0_0.0? this way you will always get the URL + the sizes with it. The old/current one you only get sizes if there is no URL.
I can definitely submit a PR
I saw you merged to master. Thanks @trevorstout !
Should the version be updated to reflect on new pod installs/updates? Do you want me to do it?
Thanks again for the fix! I pushed a new version just now (1.0.6).