How can i lock a bitmap and put pixels well in Allegro using Linux?

  allegro, c++

I ask this question becouse im using Allegro to lock a 256 * 256 BITMAP in Linux and it’s throwing me "segmentation fault". I don’t know why, it seems everything is ok, but not.

Here is my code:

#pragma once
#include <iostream>
#include <allegro5/allegro5.h>
#include <allegro5/bitmap.h>
#include <allegro5/bitmap_lock.h>
using pixel32 = std::uint32_t;
class Graph
    ALLEGRO_LOCKED_REGION* lock_bitmap = nullptr;
    ALLEGRO_BITMAP* bmp = nullptr;
    pixel32* ptr_bmp = nullptr;
    int width, height;
    Graph(int p_width, int p_height) : width(p_width), height(p_height)
    bool Init()
        return al_create_bitmap(width, height);
    void Lock()
        lock_bitmap = al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_XRGB_8888, ALLEGRO_LOCK_WRITEONLY);
        ptr_bmp = (pixel32*)lock_bitmap->data;
    void PutPixel(pixel32 pixel)
       *ptr_bmp++ = pixel;
    void Unlock(int dx, int dy, int dw, int dh)
        al_draw_scaled_bitmap(bmp, 0,0, width, height, dx, dy, dw, dh, 0);

I need PutPixel() to fill the entire surface, but it’s this the one who throws me "Segmentation Fault" in linux. The surface is power of 2, i mean 256*256, so the stride/pitch is ok. In Windows everything is OK, but when i port it to Linux blum!! the SIGV signal.
Anyway the stride is negative (-1024), so it’s up side down surface. But i think if it would be an upside down, filling the whole mem would result in an inverted image displayed.
The surface is being locked suscessfully. If it’s a RGB X888 i define pixel32 for that matter.
I have tried using al_put_pixel(x, y, pixel) and it works ok, but it’s too slow.

Any Idea?

Source: Windows Questions C++