Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 8128d70

Browse files
authored
[ios]Add errors reporting (#15391)
* add errors reporting * [ios] report error if rendering takes > 1 second. (#15633)
1 parent da6a7e9 commit 8128d70

7 files changed

Lines changed: 83 additions & 7 deletions

File tree

platform/darwin/src/MGLMapSnapshotter.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,15 @@ - (void)startWithQueue:(dispatch_queue_t)queue overlayHandler:(MGLMapSnapshotOve
252252
NSString *description = @(mbgl::util::toString(mbglError).c_str());
253253
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: description};
254254
NSError *error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeSnapshotFailed userInfo:userInfo];
255-
255+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
256+
[[MMEEventsManager sharedManager] reportError:error];
257+
#endif
256258
// Dispatch to result queue
257259
dispatch_async(queue, ^{
258260
strongSelf.completion(nil, error);
259261
strongSelf.completion = nil;
260262
});
263+
261264
} else {
262265
#if TARGET_OS_IPHONE
263266
MGLImage *mglImage = [[MGLImage alloc] initWithMGLPremultipliedImage:std::move(image) scale:strongSelf.options.scale];
@@ -636,6 +639,9 @@ + (void)completeWithErrorCode:(MGLErrorCode)errorCode description:(nonnull NSStr
636639
NSError *error = [NSError errorWithDomain:MGLErrorDomain
637640
code:errorCode
638641
userInfo:userInfo];
642+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
643+
[[MMEEventsManager sharedManager] reportError:error];
644+
#endif
639645
completion(NULL, error);
640646
});
641647
}

platform/darwin/src/MGLOfflineStorage.mm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ - (void)_addContentsOfFile:(NSString *)filePath withCompletionHandler:(void (^)(
345345
NSLocalizedDescriptionKey: description,
346346
NSLocalizedFailureReasonErrorKey: @(mbgl::util::toString(result.error()).c_str())
347347
}];
348+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
349+
[[MMEEventsManager sharedManager] reportError:error];
350+
#endif
348351
} else {
349352
auto& regions = result.value();
350353
packs = [NSMutableArray arrayWithCapacity:regions.size()];
@@ -404,6 +407,9 @@ - (void)_addPackForRegion:(id <MGLOfflineRegion>)region withContext:(NSData *)co
404407
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:errorDescription ? @{
405408
NSLocalizedDescriptionKey: errorDescription,
406409
} : nil];
410+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
411+
[[MMEEventsManager sharedManager] reportError:error];
412+
#endif
407413
}
408414
if (completion) {
409415
MGLOfflinePack *pack = mbglOfflineRegion ? [[MGLOfflinePack alloc] initWithMBGLRegion:new mbgl::OfflineRegion(std::move(mbglOfflineRegion.value()))] : nil;
@@ -441,6 +447,9 @@ - (void)_removePack:(MGLOfflinePack *)pack withCompletionHandler:(MGLOfflinePack
441447
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
442448
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
443449
}];
450+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
451+
[[MMEEventsManager sharedManager] reportError:error];
452+
#endif
444453
}
445454
if (completion) {
446455
dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
@@ -464,6 +473,9 @@ - (void)invalidatePack:(MGLOfflinePack *)pack withCompletionHandler:(void (^)(NS
464473
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
465474
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
466475
}];
476+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
477+
[[MMEEventsManager sharedManager] reportError:error];
478+
#endif
467479
}
468480
});
469481
if (completion) {
@@ -491,6 +503,9 @@ - (void)getPacksWithCompletionHandler:(void (^)(NSArray<MGLOfflinePack *> *packs
491503
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{
492504
NSLocalizedDescriptionKey: @(mbgl::util::toString(result.error()).c_str()),
493505
}];
506+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
507+
[[MMEEventsManager sharedManager] reportError:error];
508+
#endif
494509
} else {
495510
auto& regions = result.value();
496511
packs = [NSMutableArray arrayWithCapacity:regions.size()];
@@ -522,6 +537,9 @@ - (void)setMaximumAmbientCacheSize:(NSUInteger)cacheSize withCompletionHandler:(
522537
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
523538
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
524539
}];
540+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
541+
[[MMEEventsManager sharedManager] reportError:error];
542+
#endif
525543
}
526544
dispatch_sync(dispatch_get_main_queue(), ^ {
527545
completion(error);
@@ -539,6 +557,9 @@ - (void)invalidateAmbientCacheWithCompletionHandler:(void (^)(NSError *_Nullable
539557
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
540558
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
541559
}];
560+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
561+
[[MMEEventsManager sharedManager] reportError:error];
562+
#endif
542563
}
543564
dispatch_async(dispatch_get_main_queue(), ^ {
544565
completion(error);
@@ -555,6 +576,9 @@ - (void)clearAmbientCacheWithCompletionHandler:(void (^)(NSError *_Nullable erro
555576
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
556577
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
557578
}];
579+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
580+
[[MMEEventsManager sharedManager] reportError:error];
581+
#endif
558582
}
559583
dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
560584
completion(error);
@@ -571,6 +595,9 @@ - (void)resetDatabaseWithCompletionHandler:(void (^)(NSError *_Nullable error))c
571595
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{
572596
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
573597
}];
598+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
599+
[[MMEEventsManager sharedManager] reportError:error];
600+
#endif
574601
}
575602
dispatch_async(dispatch_get_main_queue(), ^{
576603
completion(error);

platform/darwin/src/MGLShape.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#import "NSString+MGLAdditions.h"
66
#import "MGLTypes.h"
77

8+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
9+
#import "MMEEventsManager.h"
10+
#endif
11+
812
#import <mbgl/util/geo.hpp>
913

1014
bool operator==(const CLLocationCoordinate2D lhs, const CLLocationCoordinate2D rhs) {
@@ -18,6 +22,9 @@ + (nullable MGLShape *)shapeWithData:(NSData *)data encoding:(NSStringEncoding)e
1822
if (!string) {
1923
if (outError) {
2024
*outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:nil];
25+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
26+
[[MMEEventsManager sharedManager] reportError:*outError];
27+
#endif
2128
}
2229
return nil;
2330
}
@@ -30,6 +37,9 @@ + (nullable MGLShape *)shapeWithData:(NSData *)data encoding:(NSStringEncoding)e
3037
*outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{
3138
NSLocalizedFailureReasonErrorKey: @(err.what()),
3239
}];
40+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
41+
[[MMEEventsManager sharedManager] reportError:*outError];
42+
#endif
3343
}
3444
return nil;
3545
}

platform/darwin/src/MGLSource.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#import "MGLMapView_Private.h"
44
#import "NSBundle+MGLAdditions.h"
55

6+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
7+
#import "MMEEventsManager.h"
8+
#endif
9+
610
#include <mbgl/style/style.hpp>
711
#include <mbgl/map/map.hpp>
812
#include <mbgl/style/source.hpp>
@@ -86,6 +90,10 @@ - (BOOL)removeFromMapView:(MGLMapView *)mapView error:(NSError * __nullable * __
8690
*outError = [NSError errorWithDomain:MGLErrorDomain
8791
code:MGLErrorCodeSourceIsInUseCannotRemove
8892
userInfo:@{ NSLocalizedDescriptionKey : localizedDescription }];
93+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
94+
[[MMEEventsManager sharedManager] reportError:*outError];
95+
#endif
96+
8997
}
9098
} else if (outError) {
9199
// TODO: Consider raising an exception here
@@ -96,6 +104,9 @@ - (BOOL)removeFromMapView:(MGLMapView *)mapView error:(NSError * __nullable * __
96104
*outError = [NSError errorWithDomain:MGLErrorDomain
97105
code:MGLErrorCodeSourceIdentifierMismatch
98106
userInfo:@{ NSLocalizedDescriptionKey : localizedDescription }];
107+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
108+
[[MMEEventsManager sharedManager] reportError:*outError];
109+
#endif
99110
}
100111

101112
return removed;

platform/darwin/src/MGLTypes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ typedef NS_ENUM(NSInteger, MGLErrorCode) {
5757
/** An error occurred while modifying the offline storage database */
5858
MGLErrorCodeModifyingOfflineStorageFailed = 9,
5959
/** Source is invalid and cannot be removed from the style (e.g. after a style change) */
60-
MGLErrorCodeSourceCannotBeRemovedFromStyle = 10
60+
MGLErrorCodeSourceCannotBeRemovedFromStyle = 10,
61+
/** An error occurred while rendering */
62+
MGLErrorCodeRenderingError = 11,
6163
};
6264

6365
/** Options for enabling debugging features in an `MGLMapView` instance. */

platform/ios/src/MGLMapView+Impl.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#import "MGLStyle_Private.h"
44
#import "NSBundle+MGLAdditions.h"
55

6+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
7+
#import "MMEEventsManager.h"
8+
#endif
9+
610
std::unique_ptr<MGLMapViewImpl> MGLMapViewImpl::Create(MGLMapView* nativeView) {
711
return std::make_unique<MGLMapViewOpenGLImpl>(nativeView);
812
}
@@ -61,6 +65,9 @@
6165
NSLocalizedFailureReasonErrorKey: @(what.c_str()),
6266
};
6367
NSError *error = [NSError errorWithDomain:MGLErrorDomain code:code userInfo:userInfo];
68+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
69+
[[MMEEventsManager sharedManager] reportError:error];
70+
#endif
6471
[mapView mapViewDidFailLoadingMapWithError:error];
6572
}
6673

platform/ios/src/MGLMapView+OpenGL.mm

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#import "MGLLoggingConfiguration_Private.h"
33
#import "MGLMapView+OpenGL.h"
44

5+
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
6+
#import "MMEConstants.h"
7+
#import "MGLMapboxEvents.h"
8+
#endif
9+
510
#include <mbgl/gl/renderable_resource.hpp>
611

712
#import <GLKit/GLKit.h>
@@ -96,7 +101,7 @@ void bind() override {
96101

97102
void MGLMapViewOpenGLImpl::display() {
98103
auto& resource = getResource<MGLMapViewOpenGLRenderableResource>();
99-
#ifdef MGL_RECREATE_GL_IN_AN_EMERGENCY
104+
100105
// See https://github.com/mapbox/mapbox-gl-native/issues/14232
101106
// glClear can be blocked for 1 second. This code is an "escape hatch",
102107
// an attempt to detect this situation and rebuild the GL views.
@@ -106,14 +111,22 @@ void bind() override {
106111
CFTimeInterval after = CACurrentMediaTime();
107112

108113
if (after - before >= 1.0) {
114+
#ifdef MGL_RECREATE_GL_IN_AN_EMERGENCY
109115
dispatch_async(dispatch_get_main_queue(), ^{
110116
emergencyRecreateGL();
111117
});
112-
}
113-
}
114-
else
118+
#else
119+
static dispatch_once_t onceToken;
120+
dispatch_once(&onceToken, ^{
121+
NSError *error = [NSError errorWithDomain:MGLErrorDomain
122+
code:MGLErrorCodeRenderingError
123+
userInfo:@{ NSLocalizedFailureReasonErrorKey :
124+
@"https://github.com/mapbox/mapbox-gl-native/issues/14232" }];
125+
[[MMEEventsManager sharedManager] reportError:error];
126+
});
115127
#endif
116-
{
128+
}
129+
} else {
117130
[resource.glView display];
118131
}
119132
}

0 commit comments

Comments
 (0)