What if an App Crashes?

Say an app was published on the App Store, and something within the code made the app unable to continue. In Codea when that happens the in game menu shows up, and tells you that there is an error. However, it also does that in Xcode. I know a game shouldn’t have any bugs if it is to be published, but we have all experienced an app crash because of a rare error that may have been overlooked. So my question is, how do you get rid of the Codea crash menu that appears? If my app does crash I want it to automatically exit like every other app does. Thanks!

@YoloSwag pm someone like @Zoyt I’m sure he’s handled something like this. I think it should be added as an option in export to disable error calls.

Maybe use something like pcall to catch the errors and then just restart the app?

@JakAttak how do you propose I use pcall with so much code? Wouldn’t using pcall on all of the code slow things down?

@Luatee, I’m not sure, but I would think it wouldn’t slow things down too much.

@Luatee. Sorry, but how do you pm someone on this forum?

@YoloSwag, you have two ways:

  1. Click on their name to view their profile, underneath their avatar it should say “Send a message”

  2. Click inbox at the top of the page, click start a new conversation, and put their forum name in the recipients slot

Haha. Thanks @Luatee for tagging me on things like this. I never actually got around to it, but here how you would handle something like an error (it requires to use Xcode, by the way):

  • In the CodeaAddOn class, there is a callback called - (void) codea:(CodeaViewController*)controller didChangeViewMode:(CodeaViewMode)mode;
  • Make an add on and add that function to the code.
  • Then, test if the view mode was changed to something other than fullscreen with no buttons
  • If so, then call - (void) setViewMode:(CodeaViewMode)viewMode animated:(BOOL)animated; in the CodeaViewController to set the view mode back to fullscreen.

The other option is to repeat steps 1 and 2, but in - (void) codea:(CodeaViewController*)controller didChangeViewMode:(CodeaViewMode)mode; execute a Lua script to restart the app. (I’m not sure how this would work, you might have to just reload the project with - (void) loadProjectAtPath:(NSString*)path;).

Sorry I couldn’t write all the code for you, I’m a bit rusty on using the Xcode side of Codea and I’m a bit limited on time.

I hope that helps.


@Zoyt Who else can we rely on? :))
makes sense, thanks. I’ve stuck this in my notes for later use.

@Luatee - Haha. Thanks. Glad I can help! Let me know if you need help implementing it, and I’ll go digging through old code.

@YoloSwag - Well, that’s what I’m here for. Glad I can help. About the issue, you didn’t put any code in that would prevent the sidebar from showing. You successfully setup an add-on, but that’s it. To fix it, let’s start with this (I’m going to run you through this step by step so I don’t overwhelm you):
First of all, you see the function - (void) codea:(CodeaViewController*)controller didChangeViewMode:(CodeaViewMode)mode? Inside of that, call something along the lines of (I’m not quite sure, since I haven’t coded it yet) [self.codeaViewController setViewMode: CodeaViewModeFullscreenNoButtons animated: FALSE];. LMK if that works.

Sorry guys, but after making the add on, I don’t really know what to do in my add-on class. I have added this function to ErrorAddon.m :

  • (void) codea:(CodeaViewController*)controller didChangeViewMode:(CodeaViewMode)mode;

But does anyone know what more I need to add to this function?

@Luatee and @JakAttak.

read what @Zoyt said, he explains two options for what to put in that function and what they will do

@JakAttak. I did, however when I tried it out in Xcode, the Codea error log still showed up.

@YoloSwag - If yo publish your code, I’m willing to review it and see what’s wrong, if there is something wrong.

Thank you @Zoyt. This means a lot to me.
Here is ErrorAddOn.h and ErrorAddOn.m

#import <UIKit/UIKit.h>
#import "CodeaAddon.h"
#import <Foundation/Foundation.h>

@interface ErrorAddOn : UIViewController


Here is ErrorAddOn.m

#import "ErrorAddOn.h"

@interface ErrorAddOn ()


@implementation ErrorAddOn

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    return self;

- (void)viewDidLoad
    [super viewDidLoad];
    // Do any additional setup after loading the view.

- (void)didReceiveMemoryWarning
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

- (void) codea:(CodeaViewController*)controller didChangeViewMode:(CodeaViewMode)mode
- (void) loadProjectAtPath:(NSString*)path


And this is my CodeaViewController

#import <UIKit/UIKit.h>

@protocol CodeaAddon;

typedef enum CodeaViewMode
} CodeaViewMode;

@interface CodeaViewController : UIViewController

@property (nonatomic, assign) CodeaViewMode viewMode;
@property (nonatomic, assign) BOOL paused;

- (void) setViewMode:(CodeaViewMode)viewMode animated:(BOOL)animated;

- (void) loadProjectAtPath:(NSString*)path;

- (void) registerAddon:(id<CodeaAddon>)addon;