![]() |
|
Keyboard Event Issue (aka: The Tales of a man who didn't knew how to code) |
mumu1000
Member #16,842
April 2018
|
Hello everybody ! I'm trying to use a really simple test code: 1#include <iostream>
2#include "allegro5/allegro.h"
3
4int main(int argc, char **argv)
5{
6 al_init();
7 ALLEGRO_DISPLAY * mainDisplay = al_create_display(1200,700);
8 if(!al_install_keyboard())
9 {
10 cout << "Keyboard Installation Failed";
11 return 1;
12 }
13 ALLEGRO_EVENT_SOURCE * keyboardEventSource = al_get_keyboard_event_source();
14 ALLEGRO_EVENT_QUEUE * keyboardEventQueue = al_create_event_queue();
15 ALLEGRO_EVENT * keyboardEvent;
16 al_register_event_source(keyboardEventQueue,keyboardEventSource);
17 do
18 {
19 while (!al_get_next_event(keyboardEventQueue,keyboardEvent))
20 {
21 } //I know this while loop is ugly, but thats just a test code OK ? ;)
22 //It crashes here (when i press a key down)... :-/
23 }while (keyboardEvent->type != ALLEGRO_EVENT_KEY_DOWN);
24
25 int key = keyboardEvent->keyboard.keycode;
26 cout << key;
27 return 0;
28}
Everything works fine, until i press a key, then my program crashes with this error code: 0xC0000005 (no more comments) Where did I make a mistake ? Thanks for your help ! PS: I'm on Win10 and i'm using C::B |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
mumu1000 said: That should be an ALLEGRO_EVENT, not an ALLEGRO_EVENT*. A pointer is an address, and in this case you didn't initialize the value either. So when al_wait_for_event returns and tries to fill in the data at the address of the ALLEGRO_EVENT you passed into it, it crashes, with an access violation. 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 |
mumu1000
Member #16,842
April 2018
|
Thank you alot (again ;p ) I think it will solve my problem ! |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
That should fix it. Bump if you have questions. 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
![]() |
ALLEGRO_EVENT keyboardEvent; ... // also change this to pass the address of the event object
while (!al_get_next_event(keyboardEventQueue, &keyboardEvent))
|
bamccaig
Member #7,536
July 2006
![]() |
DanielH said: &keyboardEvent FTFY. The address-of ('&') operator in C returns the address of its operand. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Niunio
Member #1,975
March 2002
![]() |
Looks like DanielH is using Pascal or some other Wirth-lesque language. ----------------- |
mumu1000
Member #16,842
April 2018
|
Thanks alot for your replies ! |
|