![]() |
|
Allegro Access Violation while Drawing |
RickOwensFit
Member #20,182
May 2021
|
Hey guys, I'm trying to use Allegro to draw some shapes for a school project. I got the error: Process returned -1073741819 (0xC0000005). This was the same error I got when I tried to draw bitmaps previously. I borrowed code that my teacher uses for a demo to see if it was just my code that was the problem. I am still getting the same error. From my research, 0xC0000005 seems to be an access violation error. I believe that it is a problem with my computer, what can I do to fix? Thank you. Attached below is the code from my teacher that I am using. Other Allegro functions that do not require drawing shapes, such as creating a pop-up or drawing a single pixel work. 1// Here is your first line. You must include the allegro header file or else nothing will work!
2#include <allegro5/allegro.h>// You must include the Allegro Header file
3#include <allegro5/allegro_primitives.h>
4#include <allegro5/allegro_native_dialog.h>
5
6// lots of colours to choose from
7#define RED al_map_rgb(230, 25, 75)
8#define GREEN al_map_rgb(60, 180, 75)
9#define YELLOW al_map_rgb(255, 225, 25)
10#define BLUE al_map_rgb(0, 130, 200)
11#define ORANGE al_map_rgb(245, 130, 48)
12#define PURPLE al_map_rgb(145, 30, 180)
13#define CYAN al_map_rgb(70, 240, 240)
14#define MAGENTA al_map_rgb(240, 50, 230)
15#define LIME al_map_rgb(210, 245, 60)
16#define PINK al_map_rgb(250, 190, 190)
17#define TEAL al_map_rgb(0, 128, 128)
18#define LAVENDER al_map_rgb(230, 190, 255)
19#define BROWN al_map_rgb(170, 110, 40)
20#define BEIGE al_map_rgb(255, 250, 200)
21#define MAROON al_map_rgb(128, 0, 0)
22#define MINT al_map_rgb(170, 255, 195)
23#define OLIVE al_map_rgb(128, 128, 0)
24#define CORAL al_map_rgb(255, 215, 180)
25#define NAVY al_map_rgb(0, 0, 128)
26#define GREY al_map_rgb(128, 128, 128)
27#define WHITE al_map_rgb(255, 255, 255)
28#define BLACK al_map_rgb(0, 0, 0)
29
30const int SCREEN_W = 640; // screen width
31const int SCREEN_H = 480; // screen height
32
33int main(int argc, char *argv[]) {
34 ALLEGRO_DISPLAY *display = nullptr;
35
36 // Initialize Allegro
37 al_init();
38
39 // Initialize display
40 display = al_create_display(SCREEN_W, SCREEN_H);
41 if (!display) {
42 al_show_native_message_box(display, "Error", "Error", "Failed to initialize display!",
43 nullptr, ALLEGRO_MESSAGEBOX_ERROR);
44 return -1;
45 }
46 al_set_window_title(display, "Allegro Example 8 - Shapes");
47
48 // Initialize primative add on
49 if (!al_init_primitives_addon()) {
50 al_show_native_message_box(display, "Error", "Error", "Failed to initialize primatives addon!",
51 nullptr, ALLEGRO_MESSAGEBOX_ERROR);
52 return -1;
53 }
54
55 // paint rectangle (x1, y1, x2, y2, colour) - Upper left and lower right points of the rectangle
56 al_draw_filled_rectangle(100, 100, 200, 150, MAROON);
57 al_draw_filled_circle(100, 100, 50, LAVENDER);
58 al_draw_circle(400, 400, 80, TEAL, 10); // last parameter is thickness of line
59 al_draw_line(10, 240, 310, 250, NAVY, 25);
60
61 // display what has been drawn
62 al_flip_display();
63
64 // Wait for a 5 seconds before destroy the dispaly and exit the program.
65 al_rest(5);
66 al_destroy_display(display);
67 return 0;
68}
|
DanielH
Member #934
January 2001
![]() |
You are saying it works if you comment out the draw functions? Or it doesn't work at all? Do you have a step-by-step debugger to go through each line to find out where it breaks? also, when you post code put it inside the code tags please. Makes it easier to read and allegro functions link to the manual (Even though they need updated) <code> //source code goes here </code>
|
Peter Hull
Member #1,136
March 2001
|
One thing I noticed is that you're not calling `al_init_native_dialog_addon`
|
DanielH
Member #934
January 2001
![]() |
But that would only matter if something went wrong creating display or initializing primitives. Correct? Otherwise those calls would never be called to cause issues with native dialog not being initialized. |
RickOwensFit
Member #20,182
May 2021
|
DanielH, it is breaking at the draw functions. If I comment out lines 56 through 59 it works perfectly. It creates a window titled "Allegro Example 8 - Shapes", waits, then closes. From my previous work with Allegro, I can create pop-ups and draw individual pixels as well. I believe that the problem lies with my computer, as this code works on my teacher's. |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
You're not checking the return value of al_init. If it fails, it means your runtime version of allegro is not the same as your compile time allegro. Delete old copies of allegro and relink. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
DanielH
Member #934
January 2001
![]() |
Yes, get a clean copy of Allegro. Your code is fine. {"name":"612951","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/2\/d2947eb60dfa50439cdb105ce1527fbf.png","w":648,"h":524,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/2\/d2947eb60dfa50439cdb105ce1527fbf"} |
|