maps icon indicating copy to clipboard operation
maps copied to clipboard

[Bug]: iOS Crash when invoking offlinemanager.createPack() when there Token not set

Open dv01sw opened this issue 9 months ago • 2 comments

Mapbox Implementation

Mapbox

Mapbox Version

default

React Native Version

0.76.9

Platform

iOS

@rnmapbox/maps version

10.1.33

Standalone component to reproduce

The below code works fine when the device has internet connection. If I switch the wifi off, there is a fatal crash when trying to download. Attached is the crash report from the simulator, but it crashes on physical device as well.


const OFFLINE_BOUNDS = {
  west: 8.0,
  south: 40.0,
  east: 24.0,
  north: 50.0,
};
export const downloadOfflineMap = async (
  onStateChange: (downloadProgress: DownloadProgress) => void,
): Promise<void> => {
  try {
    // Check if offline manager is available
    if (!Mapbox.offlineManager) {
      console.error('Offline manager not available');
      Alert.alert('Error', 'Map download is not available on this device');
      onStateChange({state: DownloadState.ERROR, progress: 0});
      return;
    }

    const currentState = await checkOfflineMapStatus();
    if (currentState === DownloadState.DOWNLOADED) {
      Alert.alert('Info', 'Offline map is already downloaded');
      onStateChange({state: DownloadState.DOWNLOADED, progress: 100});
      return;
    }

    onStateChange({state: DownloadState.DOWNLOADING, progress: 0});

    const errorListener = (_region: any, err: object) => {
      console.error('Offline pack error:', err);
      Alert.alert('Error', 'Failed to download offline map');
      onStateChange({state: DownloadState.ERROR, progress: 0});
    };

    const progressListener = (_region: any, progress: any) => {
      try {
        const percentage = Math.round(progress.percentage);
        const state =
          percentage === 100
            ? DownloadState.DOWNLOADED
            : DownloadState.DOWNLOADING;
        console.log(`Download progress: ${percentage}%`);
        onStateChange({
          state,
          progress: percentage,
        });
      } catch (error) {
        console.error('Error in progress listener:', error);
      }
    };

    // Attention: The MapBox API limits offlinepacks to 750 Tiles.
    // The current bounds and zoom level fit it, if you change them they
    // might break
    try {
      await Mapbox.offlineManager.createPack(
        {
          name: mapName,
          styleURL: Mapbox.StyleURL.Outdoors,
          bounds: [
            [OFFLINE_BOUNDS.east, OFFLINE_BOUNDS.north],
            [OFFLINE_BOUNDS.west, OFFLINE_BOUNDS.south],
          ],
          minZoom: 5,
          maxZoom: 10,
        },
        progressListener,
        errorListener,
      );
    } catch (createPackError) {
      console.error('Error creating offline pack:', createPackError);
      Alert.alert('Error', 'Failed to download offline map');
      onStateChange({state: DownloadState.ERROR, progress: 0});
    }
  } catch (error) {
    console.error('Error downloading offline map:', error);
    Alert.alert('Error', 'Failed to download offline map');
    onStateChange({state: DownloadState.ERROR, progress: 0});
  }
};

Observed behavior and steps to reproduce

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Incident Identifier: 67FAC32D-2338-4146-9615-82D54B40DA46
CrashReporter Key:   31D9AA9E-18B9-2787-CA0B-DF574E12364D
Hardware Model:      MacBookPro18,1
Process:             AppName [27754]
Path:                /Users/USER/Library/Developer/CoreSimulator/Devices/11841B2B-2272-41A2-9E28-E1506B22D8DD/data/Containers/Bundle/Application/A52C76A1-B31F-4177-B230-F4F84DE4873F/AppName.app/AppName
Identifier:          org.sw.AppName
Version:             1.0.3 (1.0.3)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [14442]
Coalition:           com.apple.CoreSimulator.SimDevice.11841B2B-2272-41A2-9E28-E1506B22D8DD [89028]
Responsible Process: SimulatorTrampoline [93235]

Date/Time:           2025-04-07 08:55:42.2292 +0200
Launch Time:         2025-04-07 08:55:35.1537 +0200
OS Version:          macOS 15.3.2 (24D81)
Release Type:        User
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000100e5f064
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [27754]

Triggered by Thread:  0

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   AppName                  	       0x100e5f064 RNMBXOfflineModule.offlineManager.getter + 440
1   AppName                  	       0x100e62d58 RNMBXOfflineModule.startLoading(pack:) + 728 (RNMBXOfflineModule.swift:375)
2   AppName                  	       0x100e600a8 closure #1 in RNMBXOfflineModule.createPack(_:resolver:rejecter:) + 2596 (RNMBXOfflineModule.swift:184)
3   AppName                  	       0x10082ce14 thunk for @escaping @callee_guaranteed () -> () + 28
4   libdispatch.dylib             	       0x18017b314 _dispatch_call_block_and_release + 24
5   libdispatch.dylib             	       0x18017cc08 _dispatch_client_callout + 16
6   libdispatch.dylib             	       0x18018bc2c _dispatch_main_queue_drain + 1276
7   libdispatch.dylib             	       0x18018b720 _dispatch_main_queue_callback_4CF + 40
8   CoreFoundation                	       0x18041cdbc __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
9   CoreFoundation                	       0x180417318 __CFRunLoopRun + 1944
10  CoreFoundation                	       0x180416704 CFRunLoopRunSpecific + 552
11  GraphicsServices              	       0x190604b10 GSEventRunModal + 160
12  UIKitCore                     	       0x185b39180 -[UIApplication _run] + 796
13  UIKitCore                     	       0x185b3d378 UIApplicationMain + 124
14  AppName                  	       0x100820c5c main + 80 (main.m:7)
15  dyld_sim                      	       0x102091410 start_sim + 20
16  dyld                          	       0x101f6e274 start + 2840

Thread 1:
0   libsystem_pthread.dylib       	       0x101d9e92c start_wqthread + 0

Thread 2:: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib        	       0x101e75390 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x101e866e0 mach_msg2_internal + 76
2   libsystem_kernel.dylib        	       0x101e7d4f4 mach_msg_overwrite + 536
3   libsystem_kernel.dylib        	       0x101e756cc mach_msg + 20
4   CoreFoundation                	       0x18041cae0 __CFRunLoopServiceMachPort + 156
5   CoreFoundation                	       0x180417008 __CFRunLoopRun + 1160
6   CoreFoundation                	       0x180416704 CFRunLoopRunSpecific + 552
7   Foundation                    	       0x180f1f490 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 208
8   Foundation                    	       0x180f1f6b0 -[NSRunLoop(NSRunLoop) runUntilDate:] + 60
9   UIKitCore                     	       0x185be6a34 -[UIEventFetcher threadMain] + 404
10  Foundation                    	       0x180f462d8 __NSThread__start__ + 720
11  libsystem_pthread.dylib       	       0x101da36f8 _pthread_start + 104
12  libsystem_pthread.dylib       	       0x101d9e940 thread_start + 8

Thread 3:
0   libsystem_pthread.dylib       	       0x101d9e92c start_wqthread + 0

Thread 4:
0   libsystem_pthread.dylib       	       0x101d9e92c start_wqthread + 0

Thread 5:: com.facebook.react.JavaScript
0   libsystem_kernel.dylib        	       0x101e75390 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x101e866e0 mach_msg2_internal + 76
2   libsystem_kernel.dylib        	       0x101e7d4f4 mach_msg_overwrite + 536
3   libsystem_kernel.dylib        	       0x101e756cc mach_msg + 20
4   CoreFoundation                	       0x18041cae0 __CFRunLoopServiceMachPort + 156
5   CoreFoundation                	       0x180417008 __CFRunLoopRun + 1160
6   CoreFoundation                	       0x180416704 CFRunLoopRunSpecific + 552
7   AppName                  	       0x100b80e54 +[RCTCxxBridge runRunLoop] + 212 (RCTCxxBridge.mm:350)
8   Foundation                    	       0x180f462d8 __NSThread__start__ + 720
9   libsystem_pthread.dylib       	       0x101da36f8 _pthread_start + 104
10  libsystem_pthread.dylib       	       0x101d9e940 thread_start + 8

Thread 6:: hades
0   libsystem_kernel.dylib        	       0x101e7882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x101da3c98 _pthread_cond_wait + 1192
2   libc++.1.dylib                	       0x18030529c std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 24
3   hermes                        	       0x1034085b8 hermes::vm::HadesGC::Executor::worker() + 116
4   hermes                        	       0x103408520 void* std::__1::__thread_proxy[abi:v160006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, hermes::vm::HadesGC::Executor::Executor()::'lambda'()>>(void*) + 44
5   libsystem_pthread.dylib       	       0x101da36f8 _pthread_start + 104
6   libsystem_pthread.dylib       	       0x101d9e940 thread_start + 8

Thread 7:: com.mapbox.common.Worker 1
0   libsystem_kernel.dylib        	       0x101e7882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x101da3c98 _pthread_cond_wait + 1192
2   libc++.1.dylib                	       0x18030532c std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>>) + 96
3   MapboxCommon                  	       0x1027ea460 0x10277c000 + 451680
4   libsystem_pthread.dylib       	       0x101da36f8 _pthread_start + 104
5   libsystem_pthread.dylib       	       0x101d9e940 thread_start + 8

Thread 8:: com.mapbox.common.Worker 2
0   libsystem_kernel.dylib        	       0x101e7882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x101da3c98 _pthread_cond_wait + 1192
2   libc++.1.dylib                	       0x18030532c std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>>) + 96
3   MapboxCommon                  	       0x1027ea460 0x10277c000 + 451680
4   libsystem_pthread.dylib       	       0x101da36f8 _pthread_start + 104
5   libsystem_pthread.dylib       	       0x101d9e940 thread_start + 8

Thread 9:: com.mapbox.common.Worker 3
0   libsystem_kernel.dylib        	       0x101e7882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x101da3c98 _pthread_cond_wait + 1192
2   libc++.1.dylib                	       0x18030532c std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>>) + 96
3   MapboxCommon                  	       0x1027ea460 0x10277c000 + 451680
4   libsystem_pthread.dylib       	       0x101da36f8 _pthread_start + 104
5   libsystem_pthread.dylib       	       0x101d9e940 thread_start + 8

Thread 10:: com.mapbox.common.Worker 4
0   libsystem_kernel.dylib        	       0x101e7882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x101da3c98 _pthread_cond_wait + 1192
2   libc++.1.dylib                	       0x18030532c std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>>) + 96
3   MapboxCommon                  	       0x1027ea460 0x10277c000 + 451680
4   libsystem_pthread.dylib       	       0x101da36f8 _pthread_start + 104
5   libsystem_pthread.dylib       	       0x101d9e940 thread_start + 8

Thread 11:
0   libsystem_pthread.dylib       	       0x101d9e92c start_wqthread + 0


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x000000016f5e0de8   x2: 0x0000000100e5ef78   x3: 0x00000001011c4f68
    x4: 0x0000000000000000   x5: 0x0000000000000000   x6: 0x0000600000c64d50   x7: 0x0000000000000000
    x8: 0x0000000000000000   x9: 0x0000000000000000  x10: 0x0000000000000154  x11: 0x0000000000000d50
   x12: 0x00000000000007fb  x13: 0x00000000000007fd  x14: 0x000000008268c848  x15: 0x000000008248c051
   x16: 0x0000000101d9e9b0  x17: 0x0000000000000048  x18: 0x0000000000000000  x19: 0x0000600002c2e300
   x20: 0x000000016f5e0db0  x21: 0x0000000000000040  x22: 0x000000016f5e0d90  x23: 0x000000016f5e0d70
   x24: 0x000000016f5e0d00  x25: 0x0000000101138f68  x26: 0x0000000101185008  x27: 0x0000000000000000
   x28: 0x00000001011c4f68   fp: 0x000000016f5e0e50   lr: 0x0000000100e5ef78
    sp: 0x000000016f5e0d00   pc: 0x0000000100e5f064 cpsr: 0x60001000
   far: 0x0000000000000000  esr: 0xf2000001 (Breakpoint) brk 1

Binary Images:
       0x101f68000 -        0x101febfff dyld (*) <398a133c-9bcb-317f-a064-a40d3cea3c0f> /usr/lib/dyld
       0x10081c000 -        0x101073fff org.sw.AppName (1.0.3) <faaedfb6-ec81-33b2-a885-b42893f5cf9d> /Users/USER/Library/Developer/CoreSimulator/Devices/11841B2B-2272-41A2-9E28-E1506B22D8DD/data/Containers/Bundle/Application/A52C76A1-B31F-4177-B230-F4F84DE4873F/AppName.app/AppName
       0x102090000 -        0x1020d3fff dyld_sim (*) <aca24c59-ce20-396e-8cae-200a0022fe6f> /Volumes/VOLUME/*/dyld_sim
       0x10277c000 -        0x102a13fff com.mapbox.common (23.11.4) <2c1edbad-09e0-348c-adb3-f9dc88c10040> /Users/USER/Library/Developer/CoreSimulator/Devices/11841B2B-2272-41A2-9E28-E1506B22D8DD/data/Containers/Bundle/Application/A52C76A1-B31F-4177-B230-F4F84DE4873F/AppName.app/Frameworks/MapboxCommon.framework/MapboxCommon
       0x104490000 -        0x104ba7fff com.mapbox.maps (0.0.1) <212a89bf-f66f-3e97-a49f-426f61b66c3a> /Users/USER/Library/Developer/CoreSimulator/Devices/11841B2B-2272-41A2-9E28-E1506B22D8DD/data/Containers/Bundle/Application/A52C76A1-B31F-4177-B230-F4F84DE4873F/AppName.app/Frameworks/MapboxCoreMaps.framework/MapboxCoreMaps
       0x101e2c000 -        0x101e53fff com.mapbox.MapboxMobileEvents (2.0.0) <19475912-a570-3876-b0d9-38771c6bdce8> /Users/USER/Library/Developer/CoreSimulator/Devices/11841B2B-2272-41A2-9E28-E1506B22D8DD/data/Containers/Bundle/Application/A52C76A1-B31F-4177-B230-F4F84DE4873F/AppName.app/Frameworks/MapboxMobileEvents.framework/MapboxMobileEvents
       0x102374000 -        0x102403fff io.vlcn.crsqlite (*) <01bd5c62-4036-30bd-94be-6a5b43f03062> /Users/USER/Library/Developer/CoreSimulator/Devices/11841B2B-2272-41A2-9E28-E1506B22D8DD/data/Containers/Bundle/Application/A52C76A1-B31F-4177-B230-F4F84DE4873F/AppName.app/Frameworks/crsqlite.framework/crsqlite
       0x103340000 -        0x103533fff dev.hermesengine.iphonesimulator (0.12.0) <1421c021-9e6c-35b3-b25a-01350d9c7212> /Users/USER/Library/Developer/CoreSimulator/Devices/11841B2B-2272-41A2-9E28-E1506B22D8DD/data/Containers/Bundle/Application/A52C76A1-B31F-4177-B230-F4F84DE4873F/AppName.app/Frameworks/hermes.framework/hermes
       0x101df8000 -        0x101dfffff libsystem_platform.dylib (*) <44654135-5ba7-3ea2-b7ef-f77ad1cb1980> /usr/lib/system/libsystem_platform.dylib
       0x101e74000 -        0x101eaffff libsystem_kernel.dylib (*) <5ea2a242-9786-3af8-b8a9-7899ecc711c8> /usr/lib/system/libsystem_kernel.dylib
       0x101d9c000 -        0x101dabfff libsystem_pthread.dylib (*) <53372391-80ee-3a52-85d2-b0d39816a60b> /usr/lib/system/libsystem_pthread.dylib
       0x101f48000 -        0x101f53fff libobjc-trampolines.dylib (*) <a2df0cb8-60af-32a5-8c75-9274d09bdff8> /Volumes/VOLUME/*/libobjc-trampolines.dylib
       0x180179000 -        0x1801bdfff libdispatch.dylib (*) <ef0492a6-8ca5-38f0-97bb-df9bdb54c17a> /Volumes/VOLUME/*/libdispatch.dylib
       0x18038d000 -        0x18075afff com.apple.CoreFoundation (6.9) <6fc1e779-5846-3275-bf66-955738404cf6> /Volumes/VOLUME/*/CoreFoundation.framework/CoreFoundation
       0x190601000 -        0x190609fff com.apple.GraphicsServices (1.0) <3126e74d-fd21-3b05-9124-3b2fcf5db07a> /Volumes/VOLUME/*/GraphicsServices.framework/GraphicsServices
       0x184cd9000 -        0x186a19fff com.apple.UIKitCore (1.0) <e83e0347-27d7-34bd-b0d3-51666dfdfd76> /Volumes/VOLUME/*/UIKitCore.framework/UIKitCore
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???
       0x1807da000 -        0x181416fff com.apple.Foundation (6.9) <cf6b28c4-9795-362a-b563-7b1b8c116282> /Volumes/VOLUME/*/Foundation.framework/Foundation
       0x1802e5000 -        0x180367ff3 libc++.1.dylib (*) <fb59d1e0-4df5-3571-91cf-f5a90235ba68> /Volumes/VOLUME/*/libc++.1.dylib
       0x1802b4000 -        0x1802dbff3 libdyld.dylib (*) <7b746fd7-1889-32c6-9aba-f9e091cc0210> /Volumes/VOLUME/*/libdyld.dylib

EOF

Expected behavior

No response

Notes / preliminary analysis

No response

Additional links and references

No response

dv01sw avatar Apr 07 '25 07:04 dv01sw

why would you like to use createPack when you are offline? that doesn't make any sense, you should use something like @react-native-community/netinfo or a native module if you prefer to add if offline don't execute the code

djangoamidala avatar Apr 12 '25 14:04 djangoamidala

Correction it is not a problem of connectivity. The crash only happens if MapBox.setAccessToken was not called before the function. When adding a map component and not setting the Access Token there is a error message and no crash. When downloading maps without token there is no error message and a hard crash.

dv01sw avatar Apr 13 '25 08:04 dv01sw

It's not nice, we welcome a fix. But not something we plan to address in near future

mfazekas avatar Oct 16 '25 13:10 mfazekas