Skip to content

fix(location): persist pin across restarts + prevent Stop crash before simulation#349

Closed
StephenDev0 wants to merge 1 commit intomainfrom
fix/location-pin-persistence-and-crash
Closed

fix(location): persist pin across restarts + prevent Stop crash before simulation#349
StephenDev0 wants to merge 1 commit intomainfrom
fix/location-pin-persistence-and-crash

Conversation

@StephenDev0
Copy link
Owner

Fixes #346

Summary

Two bugs are addressed in LocationSimulationView (MapSelectionView.swift):

Bug 1 – Pin disappears after restarting the app

coordinate was a pure @State value that was never written to disk. On every launch it started as nil.

Fix: Added saveCoordinate() / loadCoordinate() helpers that persist the coordinate to UserDefaults (hasPinnedLocation, pinnedLocationLat, pinnedLocationLon). saveCoordinate() is called via a didSet observer on the state property; loadCoordinate() is called in .onAppear alongside loadBookmarks(). When the pin is cleared successfully the stored flag is set to false so the map starts clean next time.

Bug 2 – App crashes when tapping "Stop" immediately after dropping a pin

The "Stop" button was shown as soon as coordinate != nil, including before "Simulate Location" had ever been tapped. Pressing it called clear_simulated_location() on C global state that had never been initialised, causing a crash.

Fix: Added an isSimulating: Bool state flag.

  • isSimulating is set to true only after simulate_location() returns 0 (success).
  • The "Stop" button is now conditionally shown (if isSimulating) — it cannot be reached before a successful simulation.
  • The "Simulate Location" button is disabled while isSimulating == true to prevent duplicate active sessions.
  • isSimulating is reset to false after a successful clear_simulated_location() call.

Testing

  1. Drop a pin → force-quit the app → reopen → pin should still be visible.
  2. Drop a pin without tapping "Simulate Location" → "Stop" button should not appear.
  3. Drop a pin → tap "Simulate Location" → tap "Stop" → should work without crashing.

…late

Fixes #346

- Add saveCoordinate()/loadCoordinate() with UserDefaults so the dropped
  pin survives app restarts.
- Introduce isSimulating flag; Stop button only shown after simulate_location()
  succeeds, preventing crash from calling clear_simulated_location() on
  uninitialised C global state.
- Disable Simulate Location button while simulation is already active.
@StephenDev0 StephenDev0 deleted the fix/location-pin-persistence-and-crash branch March 23, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Location Simulation Pin Disappears and App Crashes on Stop

1 participant