mapbox / mapbox/mapbox-maps-ios

Snapshotter can start returning duplicate snapshots after heavy use

Open
#2,340 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

Environment

  • Xcode version: 16.4 (16F6)
  • iOS version: 18.5 (22F76)
  • Devices affected: observed in simulator and on HW (iPhone 15 Pro Max)
  • Maps SDK Version: 11.12.1

Observed behavior and steps to reproduce

I have an app that can generate thousands of snapshots. Sometimes the Snapshotter gets into a state where it will return the same snapshot for every call.

Expected behavior

The correct snapshot every time :-)

Notes / preliminary analysis

I can only reproduce this sporadically, so I suspect that a race condition can lead to some kind of internal state corruption. When it is in this state, the camera will be pointing to the correct location (in the completion callback), but the snapshot is for the old location. The overlay callback is called still so it's some layer of caching before that.

I am detecting duplicates by generating a SHA256 hash of the HEIC data for the snapshots, and then checking for duplicate hashes. I have allowlisted hashes from a half dozen solid color images as these are valid duplicates.

Calling cancel before start does not prevent the issue (I serialize requests externally and have verified that that is working so I would not expect cancel to help).

Setting the snapshotSize to some other size and then back again DOES appear to work around the issue, e.g.:

    snapshotter.snapshotSize = CGSize(width: 258, height: 258)
    snapshotter.snapshotSize = CGSize(width: 256, height: 256)

Merely setting it to the same value does not impact things presumably because you're checking for that :-).

I have also seen the Snapshotter begin to produce completely transparent snapshots after experiencing this initial duplicate behavior.

Additional links and references

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing repeated Snapshotter requests under the reported iOS and Maps SDK versions, then inspect the Snapshotter behavior around repeated calls and snapshotSize changes. Compare returned image data with the requested camera location and check whether the duplicate and transparent outputs can be prevented; the issue is done when sustained use returns the correct snapshot each time.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.