summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorm-stephen <truestyle2005@163.com>2019-09-20 10:14:44 +0800
committerGitHub <noreply@github.com>2019-09-20 10:14:44 +0800
commit8128d709b62189e0745ea64be3d35e8c6dab59fa (patch)
tree0cc8d278b0a1f7ca626f5a0e67a4287d4da18ab5
parentda6a7e9318e911ab03cacde781235b50326770ec (diff)
downloadqtlocation-mapboxgl-8128d709b62189e0745ea64be3d35e8c6dab59fa.tar.gz
[ios]Add errors reporting (#15391)
* add errors reporting * [ios] report error if rendering takes > 1 second. (#15633)
-rw-r--r--platform/darwin/src/MGLMapSnapshotter.mm8
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm27
-rw-r--r--platform/darwin/src/MGLShape.mm10
-rw-r--r--platform/darwin/src/MGLSource.mm11
-rw-r--r--platform/darwin/src/MGLTypes.h4
-rw-r--r--platform/ios/src/MGLMapView+Impl.mm7
-rw-r--r--platform/ios/src/MGLMapView+OpenGL.mm23
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 <mbgl/util/geo.hpp>
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 <mbgl/style/style.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/style/source.hpp>
@@ -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> MGLMapViewImpl::Create(MGLMapView* nativeView) {
return std::make_unique<MGLMapViewOpenGLImpl>(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 <mbgl/gl/renderable_resource.hpp>
#import <GLKit/GLKit.h>
@@ -96,7 +101,7 @@ void MGLMapViewOpenGLImpl::setPresentsWithTransaction(const bool value) {
void MGLMapViewOpenGLImpl::display() {
auto& resource = getResource<MGLMapViewOpenGLRenderableResource>();
-#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];
}
}