在我的地图片段和任何其他片段之间快速切换时,出现“致命信号11(SIGSEGV)”,应用崩溃了。我已经阅读到此错误与库函数问题有关,并且我猜想它与onConnected()方法中的函数有关,因此与日志消息有关。感谢您提供有关如何解决此问题的帮助。
Relevant code:
@SuppressWarnings("MissingPermission")
override fun onStart() {
val settings = context?.getSharedPreferences(preferencesFile, Context.MODE_PRIVATE)
downloadDate = settings?.getString("lD", "").toString()
if (downloadDate != currentDate){
//some stuff that is not being executed, not relevant for the error
}
super.onStart()
if(PermissionsManager.areLocationPermissionsGranted(this.context)){
locationEngine?.requestLocationUpdates()
locationLayerPlugin?.onStart()
}
mapView.onStart()
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onPause() {
super.onPause()
mapView.onPause()
}
override fun onStop() {
val settings = context?.getSharedPreferences(preferencesFile, Context.MODE_PRIVATE)
val editor = settings?.edit()
editor?.putString("lD", downloadDate)
editor?.apply()
locationEngine?.removeLocationUpdates()
locationLayerPlugin?.onStop()
super.onStop()
mapView.onStop()
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
override fun onDestroy() {
locationEngine?.deactivate()
val settings = context?.getSharedPreferences(preferencesFile, Context.MODE_PRIVATE)
val editor = settings?.edit()
editor?.putString("shil", shilview.text.toString())
editor?.putString("dolr", dolrview.text.toString())
editor?.putString("quid", quidview.text.toString())
editor?.putString("peny", shilview.text.toString())
editor?.apply()
super.onDestroy()
mapView.onDestroy()
}
override fun onDestroyView() {
mapView.onDestroy()
super.onDestroyView()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
@SuppressWarnings("MissingPermission")
override fun onConnected() {
Log.d(t, "[onConnected] requesting location updates")
locationEngine?.requestLocationUpdates()
}
override fun onExplanationNeeded(permissionsToExplain: MutableList<String>?) {
Log.d(t, "Permissions: $permissionsToExplain")
}
override fun onLocationChanged(location: Location?) {
location?.let{
originLocation = location
setCameraPosition(location)
}
}
override fun onPermissionResult(granted: Boolean) {
Log.d(t, "[onPermissionResult] granted == $granted")
if(granted){
enableLocation()
}else{
Toast.makeText(context, "Let me know where you are. Hide and seek is not my game.", Toast.LENGTH_LONG).show()
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
private fun enableLocation(){
if (PermissionsManager.areLocationPermissionsGranted(this.context)){
Log.d(t, "Permissions granted")
initLocationEngine()
initLocationLayer()
}else{
Log.d(t, "Permissions denied")
permissionsManager = PermissionsManager(this)
permissionsManager.requestLocationPermissions(this.activity)
}
}
private fun setCameraPosition(location: Location){
map.animateCamera(CameraUpdateFactory.newLatLng(LatLng(location.latitude, location.longitude)))
}
@SuppressWarnings("MissingPermission")
private fun initLocationEngine(){
locationEngine = LocationEngineProvider(this.context).obtainBestLocationEngineAvailable()
locationEngine?.apply {
interval = 5000
fastestInterval = 1000
priority = LocationEnginePriority.HIGH_ACCURACY
activate()
}
val lastLocation = locationEngine?.lastLocation
if(lastLocation != null){
originLocation = lastLocation
setCameraPosition(lastLocation)
}else{
locationEngine?.addLocationEngineListener(this)
}
}
@SuppressWarnings("MissingPermission")
private fun initLocationLayer(){
locationLayerPlugin = LocationLayerPlugin(mapView, map, locationEngine)
locationLayerPlugin?.apply{
setLocationLayerEnabled(true)
cameraMode = CameraMode.TRACKING
renderMode = RenderMode.NORMAL
}
}
Debugger:
D/FragmentMap: Permissions granted
D/FragmentMap: [onConnected] requesting location updates
V/AudioManager: playSoundEffect effectType: 0
W/libEGL: EGLNativeWindowType 0x711ce13010 disconnect failed
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.23, mControlPoint1y = 0.06, mControlPoint2x = 0.09, mControlPoint2y = 0.97
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.6, mControlPoint1y = 0.9, mControlPoint2x = 0.8, mControlPoint2y = 1.0
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.23, mControlPoint1y = 0.06, mControlPoint2x = 0.09, mControlPoint2y = 0.97
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.6, mControlPoint1y = 0.9, mControlPoint2x = 0.8, mControlPoint2y = 1.0
V/AudioManager: playSoundEffect effectType: 0
I/zygote64: Do full code cache collection, code=1007KB, data=661KB
I/zygote64: After code cache collection, code=1003KB, data=590KB
V/Mbgl-ConnectivityReceiver: Connected: true
I/Mbgl-EGLConfigChooser: In emulator: false
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000
D/FragmentMap: Permissions granted
D/FragmentMap: [onConnected] requesting location updates
V/AudioManager: playSoundEffect effectType: 0
W/libEGL: EGLNativeWindowType 0x711ce13010 disconnect failed
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.23, mControlPoint1y = 0.06, mControlPoint2x = 0.09, mControlPoint2y = 0.97
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.6, mControlPoint1y = 0.9, mControlPoint2x = 0.8, mControlPoint2y = 1.0
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.23, mControlPoint1y = 0.06, mControlPoint2x = 0.09, mControlPoint2y = 0.97
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.6, mControlPoint1y = 0.9, mControlPoint2x = 0.8, mControlPoint2y = 1.0
V/AudioManager: playSoundEffect effectType: 0
V/Mbgl-ConnectivityReceiver: Connected: true
I/Mbgl-EGLConfigChooser: In emulator: false
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000
D/FragmentMap: Permissions granted
V/AudioManager: playSoundEffect effectType: 0
I/zygote64: Do partial code cache collection, code=1003KB, data=614KB
I/zygote64: After code cache collection, code=1003KB, data=614KB
I/zygote64: Increasing code cache capacity to 3MB
W/libEGL: EGLNativeWindowType 0x711ce13010 disconnect failed
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.23, mControlPoint1y = 0.06, mControlPoint2x = 0.09, mControlPoint2y = 0.97
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.6, mControlPoint1y = 0.9, mControlPoint2x = 0.8, mControlPoint2y = 1.0
CubicBezierInterpolator mControlPoint1x = 0.23, mControlPoint1y = 0.06, mControlPoint2x = 0.09, mControlPoint2y = 0.97
D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.6, mControlPoint1y = 0.9, mControlPoint2x = 0.8, mControlPoint2y = 1.0
D/FragmentMap: [onConnected] requesting location updates
V/AudioManager: playSoundEffect effectType: 0
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x30 in tid 7693 (.frederik.coinz)
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'
答案 0 :(得分:0)
好像您在Mapbox
中使用Fragment
。
将mapView.onDestroy()
保留在onDestroyView()
的超级调用@ Fragment
方法下面,并从mapView.onDestroy()
Fragment's
方法中取出onDestroy()
。按照this issue on github。
也请阅读how it hould be used in fragment。
您的方法将如下所示。
override fun onDestroy() {
locationEngine?.deactivate()
val settings = context?.getSharedPreferences(preferencesFile, Context.MODE_PRIVATE)
val editor = settings?.edit()
editor?.putString("shil", shilview.text.toString())
editor?.putString("dolr", dolrview.text.toString())
editor?.putString("quid", quidview.text.toString())
editor?.putString("peny", shilview.text.toString())
editor?.apply()
super.onDestroy()
//mapView.onDestroy() not required here for Fragment
}
override fun onDestroyView() {
super.onDestroyView()
mapView.onDestroy() //after super call
}