Problem solved: memory bitmaps not being converted
Andrew Gillett

I found the reason for this issue:
https://www.allegro.cc/forums/thread/618255

I was setting the bitmap flags to 0, which excludes ALLEGRO_CONVERT_BITMAPS.

I also needed to make sure that I deleted and recreated shaders when recreating the display.

UPDATE: and re-register both display (fair enough) and keyboard (unexpected) event sources.

Peter Hull

and keyboard (unexpected) event sources

Sounds like a bug. It's not needed on Mac AFAICT.

[edit]
For example, if you run this code, are you saying that it won't recognize any keys after pressing 'd' to destroy and create a display?

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3 4int main() 5{ 6 al_init(); 7 al_install_keyboard(); 8 ALLEGRO_DISPLAY *display = al_create_display(640, 480); 9 ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue(); 10 al_register_event_source(queue, al_get_keyboard_event_source()); 11 bool running = true; 12 while (running) 13 { 14 ALLEGRO_EVENT event; 15 al_wait_for_event(queue, &event); 16 if (event.type == ALLEGRO_EVENT_KEY_CHAR) 17 { 18 printf("A key %c\n", event.keyboard.unichar); 19 if (event.keyboard.unichar == 'q') 20 { 21 running = false; 22 } 23 if (event.keyboard.unichar == 'd') 24 { 25 al_destroy_display(display); 26 display = al_create_display(320, 240); 27 } 28 } 29 } 30 al_destroy_display(display); 31 return 0; 32}

I know that Windows keyboard handling needs a (focussed) window to receive the WM_KEY* messages but I thought that any window managed by Allegro would do.

Could you file an issue if you've got time?

Edgar Reynaldo

If the window is re-created, so is it's keyboard event source. I don't think it's a bug. Different HWND = different keyboard source.

Peter Hull

Isn't that an implementation detail though? From a user perspective there's nothing in the Allegro API that ties a keyboard event source to a display. Also (unless I've misunderstood what Andrew was doing) deleting the display doesn't affect the keyboard on Macos, so it is inconsistent across platforms at the least. I'm not able to test on Windows so I don't know if the code I posted works or doesn't work.

Edgar Reynaldo

Theoretically it should be re-used. I can try it.

I tested your code and in both debug and release mode I could press the d key as many times as I wanted to before pressing q to quit, or just q to quit.

Peter Hull

Thanks Edgar. I must have misunderstood what AG was saying the problem was.

Thread #618277. Printed from Allegro.cc