Having trouble finding out how to solve 0xC0000005: Access violation reading location 0x0000000000000030 [closed]

I am getting following message when i try to run my code: Unhandled exception at 0x00007FFAAA12B450 (allegro-5.2.dll) in Game.exe: 0xC0000005: Access violation reading location 0x0000000000000030.

The part that gets the error (called Background.cpp):

#include "Background.h"
#include "Constants.h"
#include <allegro5/allegro_image.h>

Background::Background(std::string filename) { 
    backgroundImage = al_load_bitmap(filename.c_str());
    if (!backgroundImage) {
        std::cout << "Could not load the background image. Please check your path correctly: " << filename << std::endl;
    }
}

void Background::update() {

    x -= 2;
    if (x < - GAME_WIDTH) x = 0;

}

void Background::render() {

    al_draw_scaled_bitmap(backgroundImage, 0, 0, al_get_bitmap_width(backgroundImage), al_get_bitmap_height(backgroundImage), x, y, GAME_WIDTH, GAME_HEIGHT, NULL);

    al_draw_scaled_bitmap(backgroundImage, 0, 0, al_get_bitmap_width(backgroundImage), al_get_bitmap_height(backgroundImage), GAME_WIDTH + x, y, GAME_WIDTH, GAME_HEIGHT, NULL);

}

void Background::dispose() {
    al_destroy_bitmap(backgroundImage);
}

Constants.h contains the constants for GAME_WIDTH and GAME_HEIGHT.

Here is my Background.h:

#pragma once
#include <iostream>
#include <allegro5/allegro.h>

class Background{
  public:
    Background(std::string filename);
    void update();
    void render();
    void dispose();

  private:
    int x;
    int y;
    ALLEGRO_BITMAP* backgroundImage = NULL;
};

Just incase i am going to show my Game.cpp and Game.h:

#include "Game.h"
#include <allegro5/allegro_image.h>

Game::Game() {}

void Game::init() {
    background = new Background("res/stars.jpg");
}

void Game::update() {
    background->update();
}

void Game::handleInput() {}

void Game::render() {
    background->render();
}

void Game::dispose() {
    background->dispose();
}
#pragma once
#include "Background.h"

class Game {
  public:
    Game();
    void init();
    void update();
    void render();
    void handleInput();
    void dispose();

  private:
    Background *background;
};

My main.cpp:

#include <iostream>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

#include "Constants.h"
#include "Game.h"

void update();
void render();
void handleInput();
void dispose();

ALLEGRO_DISPLAY *display = nullptr;
ALLEGRO_EVENT_QUEUE *event_queue = nullptr;
ALLEGRO_TIMER *timer = nullptr;

Game game;

int main() {
    if (!al_init()) return -1;

    display = al_create_display(GAME_WIDTH, GAME_HEIGHT);
    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS); // fire 60x/s

    al_install_keyboard();
    al_init_image_addon();

    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_keyboard_event_source());

    bool running = true;
    bool redraw = true;

    game.init();

    //game loop
    al_start_timer(timer);
    while (running) {
        ALLEGRO_EVENT event;
        al_wait_for_event(event_queue, &event);
        switch (event.type) {
        case ALLEGRO_EVENT_DISPLAY_CLOSE: 
            running = false; 
            break;
        case ALLEGRO_EVENT_TIMER:
            handleInput();
            update();
            redraw = true;
            break;
        }
        if (redraw && al_event_queue_is_empty(event_queue)) {
            redraw = false;
            render();
        }
    }

    dispose();


    return 0;
}

void update() {
    game.update();
}

void render() {

    //clear screen
    al_clear_to_color(al_map_rgb_f(0, 0, 0));

    //draw other game objects here
    game.render();

    // flip the page
    al_flip_display();
}

void handleInput() {
    game.handleInput();
}

void dispose() {
    game.dispose();

    al_destroy_display(display);
    al_destroy_timer(timer);
    al_destroy_event_queue(event_queue);
}

I hope you can help me with fixing this error XD.

I tried looking this error up but couldnt find annything

New contributor

Garmen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

18

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật