C++ Allegro 5 - Can't find source of access violation in visual-studio 2022

153 Views Asked by At

I'm making an atm system and I decided to use allegro as a graphics and key detection system and it's just on the keyboard that the problem is because it says there is an access violation what should I do

error in line 52:

  al_register_event_source(event_queue, al_get_keyboard_event_source());

Exception thrown at 0x00007FFDF7D82E57 (allegro-5.2.dll) in allegro.exe: 0xC0000005: Access violation reading location 0x0000000000000030.

the code:

#include <allegro5/allegro5.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>

struct painel
{
    int     atmid;
    char    contid;
    int     Minatm;
    int     Minacont;
};

struct painel tmt[40];

int i = 0;

int main()
{
    al_init();
    al_init_font_addon();
    al_init_ttf_addon();
    al_uninstall_keyboard();
    ALLEGRO_KEYBOARD_STATE keyState;


    printf(" __________________________");
    printf("\n|                          |\n| system on                |\n|power suply  is ok        |\n|__________________________|\n");
    Sleep(100);
    do {
        printf("\t starting \ \r ");
        Sleep(90);
        printf("\t starting | \r ");
        Sleep(90);
        printf("\t starting / \r ");
        Sleep(90);
        printf("\t starting | \r ");
        Sleep(90);
        printf("\t starting \ \r ");
        i++;

    } while (i <= 10);
    system("cls");
    
    
    ALLEGRO_EVENT_QUEUE* event_queue = al_create_event_queue();
    if (!event_queue) return 3;
    
    al_register_event_source(event_queue, al_get_keyboard_event_source());

    bool done = false;
    ALLEGRO_DISPLAY* display = al_create_display(1080,640);
    if (!display) return 1;
    
    ALLEGRO_FONT* font = al_load_ttf_font("COMICATE.ttf", 64, 0);
    if (!font) return -2;

    while (!done)
    {
        ALLEGRO_EVENT events;
        al_wait_for_event(event_queue, &events);

        if (events.type == ALLEGRO_EVENT_KEY_DOWN)
        {
            switch (events.keyboard.keycode)
            {
                case ALLEGRO_KEY_ESCAPE:
                done = true;
            }
        }
    }
        
    

    al_clear_to_color(al_map_rgb(180, 255, 240));
    al_draw_text(font, al_map_rgb(240, 0, 0), 20, 20, 0, "oi");
    al_set_window_title(display, "ATM");
    al_flip_display();
    al_rest(5);

    al_destroy_font(font);
    al_destroy_display(display);
    return 0;
}

i wanna a solution for this problem but i dont know what i do

0

There are 0 best solutions below