Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Sporadic exception EXC_I386_SGL using Visual Studio Code on a Mac

This thread is locked; no one can reply to it. rss feed Print
Sporadic exception EXC_I386_SGL using Visual Studio Code on a Mac
Onewing
Member #6,152
August 2005
avatar

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:

{"name":"611058","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/c\/6cf64dde34af5d77d2f96f5e7cf51cab.png","w":438,"h":159,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/c\/6cf64dde34af5d77d2f96f5e7cf51cab"}611058

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

{"name":"611059","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/2\/42fdc1f098fb17508a2a206198c2c14a.png","w":659,"h":512,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/2\/42fdc1f098fb17508a2a206198c2c14a"}611059

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.

#SelectExpand
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}

------------
Solo-Games.org | My Tech Blog: The Digital Helm

beoran
Member #12,636
March 2011

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?

SiegeLord
Member #7,827
October 2006
avatar

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

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Onewing
Member #6,152
August 2005
avatar

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:
{"name":"611062","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/7\/f72fb2c8337eb04316577192f6933298.png","w":938,"h":453,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/7\/f72fb2c8337eb04316577192f6933298"}611062

------------
Solo-Games.org | My Tech Blog: The Digital Helm

beoran
Member #12,636
March 2011

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?

SiegeLord
Member #7,827
October 2006
avatar

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

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Onewing
Member #6,152
August 2005
avatar

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

{"name":"611065","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/3\/e3ff352ebf58897ee70444693cd4de52.png","w":952,"h":220,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/3\/e3ff352ebf58897ee70444693cd4de52"}611065

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

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

------------
Solo-Games.org | My Tech Blog: The Digital Helm

beoran
Member #12,636
March 2011

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

Onewing
Member #6,152
August 2005
avatar

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

Update:
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.

{"name":"611066","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/6\/364b284b5e37af8ebefffa90e824fa9e.png","w":519,"h":362,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/6\/364b284b5e37af8ebefffa90e824fa9e"}611066
{"name":"611067","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/1\/71f0233b365a6a21ec5faf4aa50d3aca.png","w":520,"h":209,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/1\/71f0233b365a6a21ec5faf4aa50d3aca"}611067

------------
Solo-Games.org | My Tech Blog: The Digital Helm

beoran
Member #12,636
March 2011

https://stackoverflow.com/questions/28758465/dyldgdb-image-notifier-exception-when-i-run-my-application-in-device

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.

Onewing
Member #6,152
August 2005
avatar

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. :-/

------------
Solo-Games.org | My Tech Blog: The Digital Helm

SiegeLord
Member #7,827
October 2006
avatar

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.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Onewing
Member #6,152
August 2005
avatar

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.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

SiegeLord
Member #7,827
October 2006
avatar

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

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Onewing
Member #6,152
August 2005
avatar

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.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

SiegeLord
Member #7,827
October 2006
avatar

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.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

beoran
Member #12,636
March 2011

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.

Go to: