Skip to content

Conversation

@OS-pedrogustavobilro
Copy link
Contributor

PR description

The crash was occuring inside render method in Map.swift. The creation of GMapView sometimes was occuring after trying to acces it as self.mapViewController.GMapView. In such case the value was still nil, resulting in the crash when trying to unwrap the value.

The fix involved only accessing self.mapViewController.GMapView after viewDidLoad finishes and GMapView is initialized.

Possible fix for #135 and #129 (assuming they are the same issue)

Testing

You may use the example app (e2e-tests) to test and confirm that it does not crash anymore when initializing maps.

I used this block in GMViewController's viewDidLoad to better reproduce the crash:

    override func viewDidLoad() {
        super.viewDidLoad()

        DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
            let camera = GMSCameraPosition.camera(withLatitude: self.cameraPosition["latitude"] ?? 0, longitude: self.cameraPosition["longitude"] ?? 0, zoom: Float(self.cameraPosition["zoom"] ?? 12))
            let frame = CGRect(x: self.mapViewBounds["x"] ?? 0, y: self.mapViewBounds["y"] ?? 0, width: self.mapViewBounds["width"] ?? 0, height: self.mapViewBounds["height"] ?? 0)
            if let id = self.mapId {
                let gmsId = GMSMapID(identifier: id)
                self.GMapView = GMSMapView(frame: frame, mapID: gmsId, camera: camera)
            } else {
                self.GMapView = GMSMapView(frame: frame, camera: camera)
            }
            
            self.view = self.GMapView
            self.onViewDidLoad?()
        }
    }

…n Optional value"

The crash was occuring inside `render` method in `Map.swift`. The creation of `GMapView` sometimes was occuring after trying to acces it as `self.mapViewController.GMapView`. In such case the value was still nil, resulting in the crash when trying to unwrap the value.

The fix involved only accessing `self.mapViewController.GMapView` after `viewDidLoad` finishes and `GMapView` is initialized.
@OS-pedrogustavobilro OS-pedrogustavobilro merged commit e4ea913 into main Sep 23, 2025
8 checks passed
@OS-pedrogustavobilro OS-pedrogustavobilro deleted the fix/RMET-4420/crash-optional-value branch September 23, 2025 09:11
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.

4 participants