From 8128d709b62189e0745ea64be3d35e8c6dab59fa Mon Sep 17 00:00:00 2001 From: m-stephen Date: Fri, 20 Sep 2019 10:14:44 +0800 Subject: [ios]Add errors reporting (#15391) * add errors reporting * [ios] report error if rendering takes > 1 second. (#15633) --- platform/darwin/src/MGLMapSnapshotter.mm | 8 +++++++- platform/darwin/src/MGLOfflineStorage.mm | 27 +++++++++++++++++++++++++++ platform/darwin/src/MGLShape.mm | 10 ++++++++++ platform/darwin/src/MGLSource.mm | 11 +++++++++++ platform/darwin/src/MGLTypes.h | 4 +++- platform/ios/src/MGLMapView+Impl.mm | 7 +++++++ platform/ios/src/MGLMapView+OpenGL.mm | 23 ++++++++++++++++++----- 7 files changed, 83 insertions(+), 7 deletions(-) diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm index 3a258d146a..85619a780b 100644 --- a/platform/darwin/src/MGLMapSnapshotter.mm +++ b/platform/darwin/src/MGLMapSnapshotter.mm @@ -252,12 +252,15 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; NSString *description = @(mbgl::util::toString(mbglError).c_str()); NSDictionary *userInfo = @{NSLocalizedDescriptionKey: description}; NSError *error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeSnapshotFailed userInfo:userInfo]; - +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif // Dispatch to result queue dispatch_async(queue, ^{ strongSelf.completion(nil, error); strongSelf.completion = nil; }); + } else { #if TARGET_OS_IPHONE MGLImage *mglImage = [[MGLImage alloc] initWithMGLPremultipliedImage:std::move(image) scale:strongSelf.options.scale]; @@ -636,6 +639,9 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; NSError *error = [NSError errorWithDomain:MGLErrorDomain code:errorCode userInfo:userInfo]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif completion(NULL, error); }); } diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm index 32d1735bc0..95fcebc42b 100644 --- a/platform/darwin/src/MGLOfflineStorage.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -345,6 +345,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio NSLocalizedDescriptionKey: description, NSLocalizedFailureReasonErrorKey: @(mbgl::util::toString(result.error()).c_str()) }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } else { auto& regions = result.value(); packs = [NSMutableArray arrayWithCapacity:regions.size()]; @@ -404,6 +407,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:errorDescription ? @{ NSLocalizedDescriptionKey: errorDescription, } : nil]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } if (completion) { MGLOfflinePack *pack = mbglOfflineRegion ? [[MGLOfflinePack alloc] initWithMBGLRegion:new mbgl::OfflineRegion(std::move(mbglOfflineRegion.value()))] : nil; @@ -441,6 +447,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } if (completion) { dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) { @@ -464,6 +473,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } }); if (completion) { @@ -491,6 +503,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{ NSLocalizedDescriptionKey: @(mbgl::util::toString(result.error()).c_str()), }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } else { auto& regions = result.value(); packs = [NSMutableArray arrayWithCapacity:regions.size()]; @@ -522,6 +537,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } dispatch_sync(dispatch_get_main_queue(), ^ { completion(error); @@ -539,6 +557,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } dispatch_async(dispatch_get_main_queue(), ^ { completion(error); @@ -555,6 +576,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) { completion(error); @@ -571,6 +595,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif } dispatch_async(dispatch_get_main_queue(), ^{ completion(error); diff --git a/platform/darwin/src/MGLShape.mm b/platform/darwin/src/MGLShape.mm index 59643dcb6a..4ed546a3d2 100644 --- a/platform/darwin/src/MGLShape.mm +++ b/platform/darwin/src/MGLShape.mm @@ -5,6 +5,10 @@ #import "NSString+MGLAdditions.h" #import "MGLTypes.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MMEEventsManager.h" +#endif + #import bool operator==(const CLLocationCoordinate2D lhs, const CLLocationCoordinate2D rhs) { @@ -18,6 +22,9 @@ bool operator==(const CLLocationCoordinate2D lhs, const CLLocationCoordinate2D r if (!string) { if (outError) { *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:nil]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:*outError]; +#endif } return nil; } @@ -30,6 +37,9 @@ bool operator==(const CLLocationCoordinate2D lhs, const CLLocationCoordinate2D r *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{ NSLocalizedFailureReasonErrorKey: @(err.what()), }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:*outError]; +#endif } return nil; } diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm index ef23fe30e7..1d7b46e1cc 100644 --- a/platform/darwin/src/MGLSource.mm +++ b/platform/darwin/src/MGLSource.mm @@ -3,6 +3,10 @@ #import "MGLMapView_Private.h" #import "NSBundle+MGLAdditions.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MMEEventsManager.h" +#endif + #include #include #include @@ -86,6 +90,10 @@ const MGLExceptionName MGLInvalidStyleSourceException = @"MGLInvalidStyleSourceE *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeSourceIsInUseCannotRemove userInfo:@{ NSLocalizedDescriptionKey : localizedDescription }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:*outError]; +#endif + } } else if (outError) { // TODO: Consider raising an exception here @@ -96,6 +104,9 @@ const MGLExceptionName MGLInvalidStyleSourceException = @"MGLInvalidStyleSourceE *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeSourceIdentifierMismatch userInfo:@{ NSLocalizedDescriptionKey : localizedDescription }]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:*outError]; +#endif } return removed; diff --git a/platform/darwin/src/MGLTypes.h b/platform/darwin/src/MGLTypes.h index c0c93002fb..963eda384b 100644 --- a/platform/darwin/src/MGLTypes.h +++ b/platform/darwin/src/MGLTypes.h @@ -57,7 +57,9 @@ typedef NS_ENUM(NSInteger, MGLErrorCode) { /** An error occurred while modifying the offline storage database */ MGLErrorCodeModifyingOfflineStorageFailed = 9, /** Source is invalid and cannot be removed from the style (e.g. after a style change) */ - MGLErrorCodeSourceCannotBeRemovedFromStyle = 10 + MGLErrorCodeSourceCannotBeRemovedFromStyle = 10, + /** An error occurred while rendering */ + MGLErrorCodeRenderingError = 11, }; /** Options for enabling debugging features in an `MGLMapView` instance. */ diff --git a/platform/ios/src/MGLMapView+Impl.mm b/platform/ios/src/MGLMapView+Impl.mm index 9cdab4dc63..0b9ab75699 100644 --- a/platform/ios/src/MGLMapView+Impl.mm +++ b/platform/ios/src/MGLMapView+Impl.mm @@ -3,6 +3,10 @@ #import "MGLStyle_Private.h" #import "NSBundle+MGLAdditions.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MMEEventsManager.h" +#endif + std::unique_ptr MGLMapViewImpl::Create(MGLMapView* nativeView) { return std::make_unique(nativeView); } @@ -61,6 +65,9 @@ void MGLMapViewImpl::onDidFailLoadingMap(mbgl::MapLoadError mapError, const std: NSLocalizedFailureReasonErrorKey: @(what.c_str()), }; NSError *error = [NSError errorWithDomain:MGLErrorDomain code:code userInfo:userInfo]; +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR + [[MMEEventsManager sharedManager] reportError:error]; +#endif [mapView mapViewDidFailLoadingMapWithError:error]; } diff --git a/platform/ios/src/MGLMapView+OpenGL.mm b/platform/ios/src/MGLMapView+OpenGL.mm index e599024e26..ad30b608e5 100644 --- a/platform/ios/src/MGLMapView+OpenGL.mm +++ b/platform/ios/src/MGLMapView+OpenGL.mm @@ -2,6 +2,11 @@ #import "MGLLoggingConfiguration_Private.h" #import "MGLMapView+OpenGL.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MMEConstants.h" +#import "MGLMapboxEvents.h" +#endif + #include #import @@ -96,7 +101,7 @@ void MGLMapViewOpenGLImpl::setPresentsWithTransaction(const bool value) { void MGLMapViewOpenGLImpl::display() { auto& resource = getResource(); -#ifdef MGL_RECREATE_GL_IN_AN_EMERGENCY + // See https://github.com/mapbox/mapbox-gl-native/issues/14232 // glClear can be blocked for 1 second. This code is an "escape hatch", // an attempt to detect this situation and rebuild the GL views. @@ -106,14 +111,22 @@ void MGLMapViewOpenGLImpl::display() { CFTimeInterval after = CACurrentMediaTime(); if (after - before >= 1.0) { +#ifdef MGL_RECREATE_GL_IN_AN_EMERGENCY dispatch_async(dispatch_get_main_queue(), ^{ emergencyRecreateGL(); }); - } - } - else +#else + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSError *error = [NSError errorWithDomain:MGLErrorDomain + code:MGLErrorCodeRenderingError + userInfo:@{ NSLocalizedFailureReasonErrorKey : + @"https://github.com/mapbox/mapbox-gl-native/issues/14232" }]; + [[MMEEventsManager sharedManager] reportError:error]; + }); #endif - { + } + } else { [resource.glView display]; } } -- cgit v1.2.1