Sporadic exception EXC_I386_SGL using Visual Studio Code on a Mac

I have a small program that I built that puts a pink box on the display. When I run it, I sometimes get the following exception:


Sometimes I don't. Then the pink box appears and all is fine, like this:


But if I just keep debugging the program, I eventually (maybe 2 or 3 times) get the exception above. And, if I tell VS Code to keep running the program after the exception, I get a black display with no pink box. Sometimes this display is unresponsive. One time the whole mac froze and I had to restart.

I'm not sure what could be wrong and looking for clues. Here's the full code of the application. Although, considering it sometimes works, I have a feeling it's not the code and something obscure that needs to be configured on the Mac.

1#define ALLEGRO_NO_MAGIC_MAIN 2#include <allegro5/allegro.h> 3#include <iostream> 4using namespace std; 5 6const int BOUNCER_SIZE = 32; 7 8int real_main(int argc, char **argv) 9{ 10 ALLEGRO_DISPLAY *display = NULL; 11 12 if (!al_init()) 13 { 14 fprintf(stderr, "failed to initialize allegro!\n"); 15 return -1; 16 } 17 18 display = al_create_display(640, 480); 19 if (!display) 20 { 21 fprintf(stderr, "failed to create display!\n"); 22 return -1; 23 } 24 25 26 ALLEGRO_BITMAP *bouncer = NULL; 27 bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE); 28 if (!bouncer) 29 { 30 fprintf(stderr, "failed to create bouncer bitmap!\n"); 31 al_destroy_display(display); 32 return -1; 33 } 34 al_set_target_bitmap(bouncer); 35 al_clear_to_color(al_map_rgb(255, 0, 255)); 36 al_set_target_bitmap(al_get_backbuffer(display)); 37 38 while (1) 39 { 40 41 al_clear_to_color(al_map_rgb(0, 0, 0)); 42 al_draw_bitmap(bouncer, 100, 100, 0); 43 al_flip_display(); 44 } 45 46 al_destroy_display(display); 47 48 return 1; 49} 50 51int main(int argc, char **argv) 52{ 53 return al_run_main(argc, argv, real_main); 54}


Strange, looks like it should work. The only thing I can think of is that you might be linking against the wrong version of Allegro. Would that be possible?


Sounds reminiscent of https://github.com/liballeg/allegro5/issues/798, we're still investigating (I'm having trouble getting this to reproduce on my mac).

EDIT: Actually... did you install via homebrew? I see this stackoverflow issue that seems similar to yours: https://stackoverflow.com/questions/20114920/can-an-exec-bad-instruction-sigill-on-dyld-my-fault and https://github.com/Homebrew/legacy-homebrew/issues/38814


Updated this post at the bottom.

Thanks, SiegeLord and beoran! I appreciate the thoughts/suggestions.

I tried to uninstall allegro via homebrew and install again with "brew install --build-bottle allegro." I got the same results. I'll have some time tomorrow to play around with this more and will read those articles a little closer.

At this point, I'm trying to rule things out. Things I'm thinking of:

  • Is it version 5.2.2? I will try an earlier version of 5.

  • Does version 4 work?

  • Do I have multiple versions of allegro or a corrupted version somehow?

  • Is it Visual Code? During the speedhack in 2015, I used Xcode successfully.

  • Is it the version of OSX I have? If the project I built for speedhack in 2015 doesn't work in Xcode now, then my suspicion gravitates to this.

  • Is there something wrong with my code? I think I can rule this one out.

  • Is there something wrong with how I'm compiling this?

  • Did I configure the debugger wrong? In VS Code, you have to wire this in yourself.

Other things I should look into?

*** Edit on 9.27.17***
Not sure if this is a clue, but I discovered in the current setup, if I move the display window of the app across my monitors, I always get the following exception:


Could you link with the debug version of Allegro and then trace into the ogl_flush_vertex_cache function to see if anything is wrong there?

Also, is it possible on OSX that the bitmap gets "lost" like on Windows?


Hold on... do you have a backtrace for that other exception? Is it similar to this one?


Here's what I see on the call stack for the original exception I posted:


Beoran, how do I "link with the debug version"? Here's how I compile the app:

1g++ -g helloworld.cpp -Wall -ansi -o test20 -L/usr/local/lib/ -I/usr/local/include/ -lallegro


Does brew provide a debug version of Allegro? Otherwise you'll probably have to compile it yourself.


@beoran, I am not sure. I was unable to find any documentation on this or how to go about it. :'(

Here's where I'm at.
I've moved all the code into the main function, commented out "#define ALLEGRO_NO_MAGIC_MAIN" and I'm linking with "-lallegro_main". The original EXC_I386_SGL issue doesn't seem to be happening any more, but behavior is still odd. Sometimes, it executes perfectly with the expected output. Sometimes it executes and the pink box is not there. Sometimes, I get an exception, examples below. And, every once in a while, it crashes my Mac. So, still not stable.




Hmm, this is really strange behaviour. I found the link above, for what it is worth, but it seems weird that the exception is in different functions.


It is strange...but maybe not that strange?

I used VS Code option to remove all breakpoints, even though I didn't have any I had set. No change in behavior.

I opened up my work Mac laptop and did the following:

Installed homebrew
ran "brew install allegro"
It installed dependencies
Copied over the "tasks.json" file that is used to compile the code
Copied the same code to the new machine.
Compiled. I didn't attach any debuggers and just ran right from Finder.
First run: good, expected behavior
Second run: good, expected behavior
Third run: OS freeze, had to shut down

At this point, it feels like it has to do with Mac, VS Code or allegro 5.2.2. :-/


Some good news. I installed VS Code on my mac, tried your code and indeed, I get EXC_I386_SGL sporadically when I run it. However, I get no issues if I run the program manually from the command line or finder. So far, it seems like some VS Code/lldb/allegro issue.

This is separate from your other problems, but those now again sound like the bug I linked in the other thread: https://github.com/liballeg/allegro5/issues/798

Can you see if you can find the same system logs the person in that bug is looking at?

I'll keep working on it on my end, meanwhile. I really want to fix this, and I appreciate your keeping at it.


Thanks, SiegeLord. I appreciate you sticking with me.

I did three runs (all were bad runs) and captured Console messages plus a set of messages right after. They are all attached.

What I see is each run had the following:
SLPSGetCurrentProcess(): This call is deprecated and should not be called anymore.
set_foreground_operation_state(): This call is deprecated and should not be called anymore.

And shortly after that, there would be a message from the kernel process:
NVDA(Graphics): Channel exception! Exception type = 0x20 DMA Engine Error (PBDMA Error)

[Update: 10-4-17]
The Nvidia thing above got me thinking...maybe it's a problem with the graphics driver. I updated to macOS High Sierra, version 10.13. I ran the app successfully with correct output 10 times in a row. Previously, the record was 3. While I'm excited and hopeful that the worst is now behind me, I also wish I knew what the problem was and how it might've been fixed.

I still get the deprecated calls above in the Console when running the app. Technically, according to this, I think this should be resolved.


Huh! That's a bit anti-climatic. Was that 10 times in a row until a crash or 10 times and you got satisfied?


10 times with no crash, more than 3x the max I could go before. So I'm feeling pretty confident.

Tomorrow, I'm going to run through the other allegro 5 API tutorials to get a refresher. Fingers crossed this doesn't come back.

I haven't upgraded my work laptop and the error still happens there. If you wanted me to try any kind of patch, I could test it out on that machine.


Unfortunately I am still nowhere closer to figuring out what exactly could cause this. It'd really be nice to know which operation actually causes this (is it display creation? bitmap creation? one of the drawing commands?). If you could log how far the program gets before it crashes, I think that would be illuminating.


I checked but the osx GL driver uses way too few ALLEGRO_DEBUG statements. We would have to add quite a few of them to get useful logging.

Thread #617061. Printed from Allegro.cc