{"action":"closed","issue":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/5911","repository_url":"https://api.github.com/repos/mapbox/mapbox-gl-native","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/5911/labels{/name}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/5911/comments","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/5911/events","html_url":"https://github.com/mapbox/mapbox-gl-native/issues/5911","id":170125791,"number":5911,"title":"Crash in nativeCreate when OfflineManager instance is created before MapboxMap","user":{"login":"sanchin","id":1577404,"avatar_url":"https://avatars3.githubusercontent.com/u/1577404?v=3","gravatar_id":"","url":"https://api.github.com/users/sanchin","html_url":"https://github.com/sanchin","followers_url":"https://api.github.com/users/sanchin/followers","following_url":"https://api.github.com/users/sanchin/following{/other_user}","gists_url":"https://api.github.com/users/sanchin/gists{/gist_id}","starred_url":"https://api.github.com/users/sanchin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sanchin/subscriptions","organizations_url":"https://api.github.com/users/sanchin/orgs","repos_url":"https://api.github.com/users/sanchin/repos","events_url":"https://api.github.com/users/sanchin/events{/privacy}","received_events_url":"https://api.github.com/users/sanchin/received_events","type":"User","site_admin":false},"labels":[{"id":143173729,"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/labels/Android","name":"Android","color":"000000","default":false},{"id":279416951,"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/labels/offline","name":"offline","color":"fbca04","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-09T09:50:41Z","updated_at":"2017-06-20T07:31:18Z","closed_at":"2017-06-20T07:31:17Z","body":"I have an application with a separate controller for everything Mapbox related, which creates a MapFragment and shows it when needed. It also has a method to cache a region for offline use.\n\nWhen I try to show the fragment after calling `OfflineManager.getInstance(context)` the app crashes with following logs (4.1.1):\n\n```\n*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\nBuild fingerprint: 'google/shamu/shamu:6.0.1/MOB30O/2920157:user/release-keys'\nRevision: '0'\nABI: 'arm'\npid: 27189, tid: 27189, name: hybridcontainer  >>> com.example.maptest <<<\nsignal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c\n    r0 00000000  r1 00000001  r2 b6f6ec54  r3 b6f6eb34\n    r4 98a3adb0  r5 98a3adb0  r6 beb1ddd8  r7 b4ce8868\n    r8 fffff5e4  r9 b4ce8758  sl 00000000  fp 00000000\n    ip b6f6ecb4  sp beb1ddb0  lr 8f9bdde4  pc 8f9bdde4  cpsr 400d0010\n    #00 pc 0021ade4  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so (_ZN4mbgl4util7RunLoop13getLoopHandleEv+28)\n    #01 pc 00219d80  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so (_ZN4mbgl4util9AsyncTask4ImplC2EONSt3__18functionIFvvEEE+48)\n    #02 pc 00219ccc  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so (_ZN4mbgl4util9AsyncTaskC1EONSt3__18functionIFvvEEE+28)\n    #03 pc 00182b1c  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so (_ZN4mbgl3Map4ImplC2ERNS_4ViewERNS_10FileSourceENS_7MapModeENS_13GLContextModeENS_13ConstrainModeENS_12ViewportModeE+288)\n    #04 pc 00182908  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so (_ZN4mbgl3MapC1ERNS_4ViewERNS_10FileSourceENS_7MapModeENS_13GLContextModeENS_13ConstrainModeENS_12ViewportModeE+72)\n    #05 pc 000c7a38  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so (_ZN4mbgl7android13NativeMapViewC2EP7_JNIEnvP8_jobjectfij+484)\n    #06 pc 000e4ccc  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so\n    #07 pc 00fb5f19  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xad4000) (long com.mapbox.mapboxsdk.maps.NativeMapView.nativeCreate(java.lang.String, java.lang.String, java.lang.String, float, int, long)+180)\n    #08 pc 00fb55d9  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xad4000) (void com.mapbox.mapboxsdk.maps.NativeMapView.<init>(com.mapbox.mapboxsdk.maps.MapView)+980)\n    #09 pc 00f9b6a9  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xad4000) (void com.mapbox.mapboxsdk.maps.MapView.initialize(android.content.Context, com.mapbox.mapboxsdk.maps.MapboxMapOptions)+956)\n    #10 pc 00f99fa7  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xad4000) (void com.mapbox.mapboxsdk.maps.MapView.<init>(android.content.Context, com.mapbox.mapboxsdk.maps.MapboxMapOptions)+218)\n    #11 pc 00f92a79  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xad4000) (android.view.View com.mapbox.mapboxsdk.maps.MapFragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)+932)\n    #12 pc 7355cb29  /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x1ec9000)\n```\n\nI've tried to build the 4.1.1 myself to symbollicate it, but failed  (zip.h not found, I had no time to solve that yet). Building master works, but strangely it has no code references after the libmapbox-gl.so lines, so the symbollicated log looks like that:\n\n```\n********** Crash dump: **********\nBuild fingerprint: 'google/shamu/shamu:6.0.1/MOB30O/2920157:user/release-keys'\npid: 4533, tid: 4533, name: hybridcontainer  >>> com.example.maptest <<<\nsignal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20\nStack frame #00 pc 0009c378  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so: Routine ??\n??:0\nStack frame #01 pc 0009b500  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so: Routine ??\n??:0\nStack frame #02 pc 0009b458  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so: Routine ??\n??:0\nStack frame #03 pc 00061b5c  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so: Routine ??\n??:0\nStack frame #04 pc 00061998  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so: Routine ??\n??:0\nStack frame #05 pc 00049d2c  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so: Routine ??\n??:0\nStack frame #06 pc 00051294  /data/app/com.example.maptest-2/lib/arm/libmapbox-gl.so: Routine ??\n??:0\nStack frame #07 pc 00fc82d1  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xae5000) (long com.mapbox.mapboxsdk.maps.NativeMapView.nativeCreate(java.lang.String, java.lang.String, java.lang.String, float, int, long)+180)\nStack frame #08 pc 00fc7b01  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xae5000) (void com.mapbox.mapboxsdk.maps.NativeMapView.<init>(com.mapbox.mapboxsdk.maps.MapView)+996)\nStack frame #09 pc 00fac78d  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xae5000) (void com.mapbox.mapboxsdk.maps.MapView.initialize(android.content.Context, com.mapbox.mapboxsdk.maps.MapboxMapOptions)+800)\nStack frame #10 pc 00fab06f  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xae5000) (void com.mapbox.mapboxsdk.maps.MapView.<init>(android.content.Context, com.mapbox.mapboxsdk.maps.MapboxMapOptions)+234)\nStack frame #11 pc 00fa3f71  /data/app/com.example.maptest-2/oat/arm/base.odex (offset 0xae5000) (android.view.View com.mapbox.mapboxsdk.maps.MapFragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)+932)\nStack frame #12 pc 7355cb29  /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x1ec9000)\n\n```\n\nWhen I move the `OfflineManager.getInstance(context)` to onMapReady - it works, but I can't cache a region without showing the map first.\nThe (pseudo) code looks more or less like this:\n\n```\npublic void configure(String apiKey, Map somethingElse) {\n    MapboxAccountManager.start(context, apiKey);\n    final FragmentManager fragmentManager = activity.getFragmentManager();\n    mapFragment = (MapFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);\n\n    if (mapFragment == null) {\n        MapboxMapOptions options = new MapboxMapOptions();\n        options.styleUrl(Style.MAPBOX_STREETS)\n                .camera(new CameraPosition.Builder()\n                        .target(new LatLng(11, 11))\n                        .zoom(11)\n                        .build());\n        mapFragment = MapFragment.newInstance(options);\n    }\n\n    mapFragment.getMapAsync(new OnMapReadyCallback() {\n        @Override\n        public void onMapReady(MapboxMap mapboxMap) {\n            Controller.this.mapboxMap = mapboxMap;\n            ...\n            //offlineManager = OfflineManager.getInstance(context); //this works, but caching fails\n         }\n    }\n    offlineManager = OfflineManager.getInstance(context); //this passes, but causes a crash when calling show\n}\n\npublic void show() {\n    if (mapFragment != null) {\n        if (mapFragment.isAdded()) {\n            activity.getFragmentManager().beginTransaction().show(mapFragment).commit();\n        } else {\n            activity.getFragmentManager().beginTransaction().replace(R.id.container, mapFragment, FRAGMENT_TAG).commit();\n        }\n    } else {\n        throw new UnsupportedOperationException(\"please configure before show\"));\n    }\n}\n\npublic void precache(Map something) {\n    ...\n    OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(\n                    Style.MAPBOX_STREETS,\n                    bounds,\n                    minZoom,\n                    maxZoom,\n                    activity.getResources().getDisplayMetrics().density);\n    offlineManager.createOfflineRegion(definition, metadata, callback);\n}\n```\n\nSo basically, it looks like it's impossible to use OfflineManager before the MapView is created, apart from onMapReady (which is AFTER the view is created) or any other onCreateView.\n\nIs it possible to somehow separate the actual view creation from the OfflineManager logic?\n\n**Platform:** Android (5.1 and 6.0)\n**Mapbox SDK version:** 4.1.1 and 4.2.0-SNAPSHOT\n### Steps to trigger behavior\n1. Instantiate OfflineManager by calling OfflineManager.getInstance(context) before of onCreateView\n2. Create the view by using a FragmentTransaction\n3. Crash\n### Expected behavior\n\nThis shouldn't crash, at least when showing the map in online, and since no errors are thrown when calling getInstance, I'd assume it works properly.\n### Actual behavior\n\nCrash when trying to display a map, regardles of being online/oflline or having anything in cache.\n"}}
{"actor":{"display_login":"Guardiola31337"}}