Skip to content
Snippets Groups Projects
Commit 7f62de41 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

better error handling + removed dead code

parent 608dc5db
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
@public
bool compute;
NSMutableArray *errors;
}
@property (strong, nonatomic) UIWindow *window;
......@@ -12,4 +13,3 @@
@property (strong, nonatomic) SplitViewController *splitViewController; // iPad
@end
......@@ -14,7 +14,7 @@
self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
}
compute = false;
errors = [[NSMutableArray alloc] init];
// Copy resource files if the version of the app has changed
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *prefsv = [prefs stringForKey:@"OnelabModelsVersion"];
......
......@@ -22,10 +22,12 @@
/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
GLuint viewRenderbuffer, viewFramebuffer;
/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it
exists (0 if it does not exist) */
GLuint depthRenderbuffer;
BOOL rendering;
@public
/* our GModel drawing class */
drawContext *mContext;
......@@ -36,6 +38,4 @@
- (void)load:(NSString*) file;
- (UIImage*) getGLScreenshot;
@end
......@@ -149,37 +149,4 @@
}
}
- (UIImage*) getGLScreenshot
{
NSInteger myDataLength = backingWidth * backingHeight * 4;
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y <backingHeight; y++){
for(int x = 0; x <backingWidth * 4; x++){
buffer2[(backingHeight - 1 - y) * backingWidth * 4 + x] = buffer[y * 4 * backingWidth + x];
}
}
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * backingWidth;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(backingWidth, backingHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
free(buffer);
free(buffer2);
return [UIImage imageWithCGImage:imageRef];
}
- (void)saveGLScreenshotToPhotosAlbum {
UIImageWriteToSavedPhotosAlbum([self getGLScreenshot], nil, nil, nil);
}
@end
......@@ -12,7 +12,6 @@
UIBarButtonItem *_runStopButton, *_playButton, *_stopButton;
UIAlertView *_loadingAlert;
UIErrorAlertView *_errorAlert;
NSMutableArray *_errors;
UIBackgroundTaskIdentifier _computeBackgroundTaskIdentifier;
NSTimer *_animation;
}
......
......@@ -76,6 +76,12 @@
//[_loadingAlert release];
_loadingAlert = nil;
}
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if(appDelegate->errors.count > 0){
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[appDelegate->errors firstObject] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[_errorAlert show];
}
}
- (void)viewDidLoad
......@@ -85,20 +91,18 @@
[self configureView];
[_singleTap requireGestureRecognizerToFail:_doubleTap];
scaleFactor = 1.;
_errors = [[NSMutableArray alloc] init];
setObjCBridge((__bridge void*) self);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestRender) name:@"requestRender" object:nil];
_runStopButton = [[UIBarButtonItem alloc] initWithTitle:@"Run" style:UIBarButtonItemStylePlain target:self action:@selector(compute)];
//UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStyleBordered target:self action:@selector(share)];
if([[UIDevice currentDevice].model isEqualToString:@"iPad"] ||
[[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){
UIBarButtonItem *model = [[UIBarButtonItem alloc] initWithTitle:@"Model list" style:UIBarButtonItemStylePlain target:self action:@selector(showModelsList)];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_runStopButton, model, /*share,*/ nil]];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_runStopButton, model, nil]];
}
else {
UIBarButtonItem *settings = [[UIBarButtonItem alloc] initWithTitle:@"Parameters" style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_runStopButton, settings, /*share,*/ nil]];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_runStopButton, settings, nil]];
}
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
......@@ -131,16 +135,8 @@
[[UIApplication sharedApplication] endBackgroundTask: _computeBackgroundTaskIdentifier];
}
-(void)share
{
NSArray *dataToShare = @[[self.glView getGLScreenshot]];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
}
- (void)compute
{
[_errors removeAllObjects];
[_runStopButton setAction:@selector(stop)];
[_runStopButton setTitle:@"Stop"];
[_progressLabel setText:@""];
......@@ -186,8 +182,9 @@
[_progressLabel setHidden:YES];
[_progressIndicator stopAnimating];
[_progressIndicator setHidden:YES];
if(_errors.count > 0) {
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if(appDelegate->errors.count > 0){
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[appDelegate->errors firstObject] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[_errorAlert show];
}
}
......@@ -317,32 +314,23 @@
-(void)addError:(std::string)msg
{
[_errors addObject:[Utils getStringFromCString:msg.c_str()]];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate->errors addObject:[Utils getStringFromCString:msg.c_str()]];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0) {
[_errors removeAllObjects];
return;
}
else [_errors removeLastObject];
if(_errors.count > 1)
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil];
else
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles: nil];
[_errorAlert show];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate->errors removeAllObjects];
}
#pragma mark - Split view
-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return NO;
}
void messageFromCpp (void *self, std::string level, std::string msg)
{
if(level == "RequestRender"){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment