Skip to content

LatLng with double.nan in Marker/MarkerLayer triggers memory leak #2178

@xoofee

Description

@xoofee

What is the bug?

NaN LatLng point in Marker/MakerLayer cause Out of memory error
dart MarkerLayer(markers: [Marker(point: latlong2.LatLng(0/0, 0/0), child: Icon(Icons.keyboard_arrow_up, color: Colors.white, size: 20))]),

How can we reproduce it?

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart' as latlong2;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'NaN Marker Test',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MapPage(),
    );
  }
}

class MapPage extends StatelessWidget {
  const MapPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('NaN Marker OOM Test'),
      ),
      body: FlutterMap(
        options: MapOptions(
          initialCenter: latlong2.LatLng(0.0, 0.0),
          initialZoom: 2.0,
        ),
        children: [
          TileLayer(
            urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
            userAgentPackageName: 'com.example.findeasy',
          ),
          MarkerLayer(
            markers: [
              Marker(
                // point: latlong2.LatLng(0.0, 0.0), // this is ok
                point: latlong2.LatLng(0/0, 0/0), // NaN coordinates cause Out of Memory
                child: const Icon(
                  Icons.keyboard_arrow_up,
                  color: Colors.white,
                  size: 20,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

pubspec.lock

  flutter_map:
    dependency: "direct main"
    description:
      name: flutter_map
      sha256: "391e7dc95cc3f5190748210a69d4cfeb5d8f84dcdfa9c3235d0a9d7742ccb3f8"
      url: "https://pub.dev"
    source: hosted
    version: "8.2.2"

flutter --version

Flutter 3.27.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision d8a9f9a52e (11 months ago) • 2025-01-31 16:07:18 -0500
Engine • revision 82bd5b7209
Tools • Dart 3.6.2 • DevTools 2.40.3

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.27.4, on Microsoft Windows [版本 10.0.19044.1645], locale zh-CN)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[√] Visual Studio - develop Windows apps (Visual Studio 生成工具 2022 17.11.5)
[√] Android Studio (version 2024.2)

Do you have a potential solution?

Never pass NaN to marker

Metadata

Metadata

Assignees

No one assigned

    Labels

    P: 3 (low)(Default priority for feature requests)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions