Crash in iOS simulator iOS 8 when rotating screen left
jmasterx

I have just built allegro and its dependencies targeting iOS 7 and 8.

I built real device and simulator binaries. I just created a simple test program to test things out.

It is basically ex_physfs

#SelectExpand
1/* 2 * Example program for Allegro library. 3 * 4 * Demonstrate PhysicsFS addon. 5 */ 6 7 8#include <stdio.h> 9#include <allegro5/allegro.h> 10#include <allegro5/allegro_image.h> 11#include <allegro5/allegro_physfs.h> 12#include <physfs.h> 13 14#include "common.c" 15 16static void show_image(ALLEGRO_BITMAP *bmp) 17{ 18 ALLEGRO_EVENT_QUEUE *queue; 19 ALLEGRO_EVENT event; 20 21 queue = al_create_event_queue(); 22 al_register_event_source(queue, al_get_keyboard_event_source()); 23 24 while (true) { 25 al_draw_bitmap(bmp, 0, 0, 0); 26 al_flip_display(); 27 al_wait_for_event(queue, &event); 28 if (event.type == ALLEGRO_EVENT_KEY_DOWN 29 && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { 30 break; 31 } 32 } 33 34 al_destroy_event_queue(queue); 35} 36 37static void print_file(ALLEGRO_FS_ENTRY *entry) 38{ 39 int mode = al_get_fs_entry_mode(entry); 40 time_t now = time(NULL); 41 time_t atime = al_get_fs_entry_atime(entry); 42 time_t ctime = al_get_fs_entry_ctime(entry); 43 time_t mtime = al_get_fs_entry_mtime(entry); 44 const char *name = al_get_fs_entry_name(entry); 45 off_t size = al_get_fs_entry_size(entry); 46 47 log_printf("%-36s %s%s%s%s%s%s %8u %8u %8u %8u\n", 48 name, 49 mode & ALLEGRO_FILEMODE_READ ? "r" : ".", 50 mode & ALLEGRO_FILEMODE_WRITE ? "w" : ".", 51 mode & ALLEGRO_FILEMODE_EXECUTE ? "x" : ".", 52 mode & ALLEGRO_FILEMODE_HIDDEN ? "h" : ".", 53 mode & ALLEGRO_FILEMODE_ISFILE ? "f" : ".", 54 mode & ALLEGRO_FILEMODE_ISDIR ? "d" : ".", 55 (unsigned)(now - ctime), 56 (unsigned)(now - mtime), 57 (unsigned)(now - atime), 58 (unsigned)size); 59} 60 61static void listdir(ALLEGRO_FS_ENTRY *entry) 62{ 63 ALLEGRO_FS_ENTRY *next; 64 65 al_open_directory(entry); 66 while (1) { 67 next = al_read_directory(entry); 68 if (!next) 69 break; 70 71 print_file(next); 72 if (al_get_fs_entry_mode(next) & ALLEGRO_FILEMODE_ISDIR) 73 listdir(next); 74 al_destroy_fs_entry(next); 75 } 76 al_close_directory(entry); 77} 78 79static bool add_main_zipfile(void) 80{ 81 ALLEGRO_PATH *exe; 82 const char *ext; 83 const char *zipfile; 84 bool ret; 85 86 /* On Android we treat the APK itself as the zip file. */ 87 exe = al_get_standard_path(ALLEGRO_EXENAME_PATH); 88 ext = al_get_path_extension(exe); 89 if (0 == strcmp(ext, ".apk")) { 90 zipfile = al_path_cstr(exe, '/'); 91 } 92 else { 93 zipfile = "ex_physfs.zip"; 94 } 95 96 if (PHYSFS_addToSearchPath(zipfile, 1)) { 97 ret = true; 98 } 99 else { 100 log_printf("Could load the zip file: %s\n", zipfile); 101 ret = false; 102 } 103 104 al_destroy_path(exe); 105 106 return ret; 107} 108 109int main(int argc, char *argv[]) 110{ 111 ALLEGRO_DISPLAY *display; 112 ALLEGRO_BITMAP *bmp; 113 ALLEGRO_FS_ENTRY *entry; 114 int i; 115 116 if (!al_init()) { 117 abort_example("Could not init Allegro\n"); 118 } 119 al_init_image_addon(); 120 al_install_keyboard(); 121 open_log_monospace(); 122 123 /* Set up PhysicsFS. */ 124 if (!PHYSFS_init(argv[0])) { 125 abort_example("Could not init PhysFS\n"); 126 } 127 // This creates a ~/.allegro directory, which is very annoying to say the 128 // least - and no need for it in this example. 129 // if (!PHYSFS_setSaneConfig("allegro", "ex_physfs", NULL, 0, 0)) 130 // return 1; 131 if (!add_main_zipfile()) { 132 abort_example("Could not add zip file\n"); 133 } 134 135 for (i = 1; i < argc; i++) { 136 if (!PHYSFS_addToSearchPath(argv[i], 1)) { 137 abort_example("Couldn't add %s\n", argv[i]); 138 } 139 } 140 141 display = al_create_display(640, 480); 142 if (!display) { 143 abort_example("Error creating display.\n"); 144 } 145 146 /* Make future calls to al_fopen() on this thread go to the PhysicsFS 147 * backend. 148 */ 149 al_set_physfs_file_interface(); 150 151 /* List the contents of our example zip recursively. */ 152 log_printf("%-36s %-6s %8s %8s %8s %8s\n", 153 "name", "flags", "ctime", "mtime", "atime", "size"); 154 log_printf( 155 "------------------------------------ " 156 "------ " 157 "-------- " 158 "-------- " 159 "-------- " 160 "--------\n"); 161 entry = al_create_fs_entry(""); 162 listdir(entry); 163 al_destroy_fs_entry(entry); 164 165 bmp = al_load_bitmap("02.bmp"); 166 if (!bmp) { 167 /* Fallback for Android. */ 168 bmp = al_load_bitmap("assets/data/alexlogo.bmp"); 169 } 170 if (bmp) { 171 show_image(bmp); 172 al_destroy_bitmap(bmp); 173 } 174 175 PHYSFS_deinit(); 176 177 //close_log(false); 178 return 0; 179} 180 181 182/* vim: set sts=3 sw=3 et: */

When using the iOS 7 simulators, everything is working great. When I use any of the iOS 8 simulators, almost everything works, except when I rotate the screen left, I immediately get an ex_bad_access from EAGLView.m on line 192.

- (BOOL)createFramebuffer {
   ALLEGRO_DISPLAY_IPHONE *d = (ALLEGRO_DISPLAY_IPHONE *)allegro_display;

    if (d->extra->adapter == 0 && [self respondsToSelector:@selector(contentScaleFactor)]) {
        scale = self.contentScaleFactor = [[UIScreen mainScreen] scale];
        ALLEGRO_INFO("Screen scale is %f\n", self.contentScaleFactor);
    }
    else {
      scale = 1.0f;
    }

The cause of the crash is that the allegro display pointer is NULL. I do not know why. I would be tempted to do:

- (BOOL)createFramebuffer {
   ALLEGRO_DISPLAY_IPHONE *d = (ALLEGRO_DISPLAY_IPHONE *)allegro_display;

    if(d == NULL)
     return;

    if (d->extra->adapter == 0 && [self respondsToSelector:@selector(contentScaleFactor)]) {
        scale = self.contentScaleFactor = [[UIScreen mainScreen] scale];
        ALLEGRO_INFO("Screen scale is %f\n", self.contentScaleFactor);
    }

But that seems evil.

In any case I wanted to bring this to the attention of the devs. I'm using Xcode 6.1 and OSX 10.9.4.

I will soon be posting my binaries so that everyone with Xcode 6 can quickly try this for themselves. My binaries have a debug version with debug symbols.

SiegeLord

Do you have a backtrace?

jmasterx

If you mean a stack trace then I can get that to you, if not, please describe what you mean.

SiegeLord

Two terms for the same thing :).

jmasterx

I can't seem to find a way to print a stack trace, but I'll just print it myself:

#0 0x000a4280 in -[EAGLView createFramebuffer] at /Users/josh/Downloads/allegro5-5.1/src/iphone/EAGLView.m:192

EAGLView.m -> line 192
locals:

self  EAGLView *  0x7b681130  0x7b681130
_cmd  SEL  "createFramebuffer"  0x001e5c38
d  ALLEGRO_DISPLAY_IPHONE *  NULL  0x00000000
depth_stencil_format  GLint

Contents of self at this point:

self  EAGLView *  0x7b681130  0x7b681130
UIView  UIView    
context  EAGLContext *  nil  0x00000000
allegro_display  ALLEGRO_DISPLAY *  NULL  0x00000000
viewRenderbuffer  GLuint  0  0
viewFramebuffer  GLuint  0  0
depthRenderbuffer  GLuint  0  0
touch_list  _AL_LIST *  0x7b681990  0x7b681990
touch_id_set  NSMutableIndexSet *  0 indexes  0x7b6819f0
primary_touch  UITouch *  nil  0x00000000
next_free_touch_id  int  1  1
scale  float  0  0
backingWidth  GLint  0  0
backingHeight  GLint  0  0

#1 0x000a40c9 in -[EAGLView layoutSubviews] at /Users/josh/Downloads/allegro5-5.1/src/iphone/EAGLView.m:161

EAGLView.m -> line 161
locals:

self  EAGLView *  0x7b681130  0x7b681130
_cmd  SEL  "layoutSubviews"  0x01d1c520

Contents of self at this point:

self  EAGLView *  0x7b681130  0x7b681130
UIView  UIView    
context  EAGLContext *  nil  0x00000000
allegro_display  ALLEGRO_DISPLAY *  NULL  0x00000000
viewRenderbuffer  GLuint  0  0
viewFramebuffer  GLuint  0  0
depthRenderbuffer  GLuint  0  0
touch_list  _AL_LIST *  0x7b681990  0x7b681990
touch_id_set  NSMutableIndexSet *  0 indexes  0x7b6819f0
primary_touch  UITouch *  nil  0x00000000
next_free_touch_id  int  1  1
scale  float  0  0
backingWidth  GLint  0  0
backingHeight  GLint  0  0

Then:
#2 0x014a4dd1 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#44 0x014198b6 in UIApplicationMain ()
#45 0x00118a83 in +[allegroAppDelegate run::] at /Users/josh/Downloads/allegro5-5.1/src/iphone/allegroAppDelegate.m:391
Then:
iphone_main.m line 63
#46 0x00067716 in main at /Users/josh/Downloads/allegro5-5.1/src/iphone/iphone_main.m:63

Here is where Thread 7 (al_mangled_main thread is):
#0 0x02a147ca in __psynch_cvwait ()
#2 0x02a56bd9 in pthread_cond_wait$UNIX2003 ()
#3 0x00158d7a in _al_cond_wait at /Users/josh/Downloads/allegro5-5.1/misc/Allegro 5 iOS/../../include/allegro5/platform/aintuthr.h:81
#4 0x00158cf4 in al_wait_for_event at /Users/josh/Downloads/allegro5-5.1/src/events.c:392
#5 0x000189d9 in _al_mangled_main at /Users/josh/Desktop/Allegro 5.1.9 iOS/AllegroIOSTest/AllegroIOSTest/main.mm:440
#6 0x000675b0 in user_main at /Users/josh/Downloads/allegro5-5.1/src/iphone/iphone_main.m:19
#7 0x000744c1 in thread_func_trampoline at /Users/josh/Downloads/allegro5-5.1/src/threads.c:80
#8 0x0007d7a3 in thread_proc_trampoline at /Users/josh/Downloads/allegro5-5.1/src/unix/uxthread.c:44
#9 0x02a525fb in _pthread_body ()
#10 0x02a52485 in _pthread_start ()
#11 0x02a57cf2 in thread_start ()

---
I thought it only happened when I turn the device left, but as long as I have set the orientation as supported, it will cause this on iOS 8.1.

Thomas Fjellstrom
jmasterx said:

I can't seem to find a way to print a stack trace, but I'll just print it myself:

I think you can set up a trigger in XCode's debugger that fires on any exception/crash. then it should give you a backtrace on crash. Though i think it'd let you get a backtrace even if you don't if you find the debugger window.

Thread #615051. Printed from Allegro.cc