Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Mouse problems in Allegro 4.9.8

This thread is locked; no one can reply to it. rss feed Print
Mouse problems in Allegro 4.9.8
kenmasters1976
Member #8,794
July 2007

I'm writing some simple programs to learn the new API and I have this problem: al_get_mouse_state() keeps crashing on my machine. I've been trying to spot the problem and compared the code practically line to line with the one in ex_mouse_focus.c and found that the only difference was the creation of one more ALLEGRO_DISPLAY. If I create two ALLEGRO_DISPLAYs, the program no longer crashes on al_get_mouse_state().

If I create only one ALLEGRO_DISPLAY and use al_get_mouse_state(), the program crashes. Anyone else has this problem? or is there something wrong with my Allegro 4.9.8 setup?.

Thanks.

Evert
Member #794
November 2000
avatar

What platform are you using?
Also, even if it's a very simple change, please attach your example program (it's easier to compile and run yours than to modify an existing example ourselves).

kenmasters1976
Member #8,794
July 2007

I'm using MinGW on Windows XP.

I reduced the program down to this:

1#include <stdio.h>
2#include <allegro5/allegro5.h>
3 
4 
5 
6static ALLEGRO_DISPLAY *display;
7//static ALLEGRO_DISPLAY *display2 = NULL;
8 
9 
10 
11int main() {
12 ALLEGRO_LOCKED_REGION lr;
13 ALLEGRO_KEYBOARD_STATE key_state;
14 ALLEGRO_MOUSE_STATE mouse_state;
15 
16 if (!al_init()) {
17 printf("Could not init Allegro.\n");
18 return 1;
19 }
20 if (!al_install_mouse()) {
21 printf("Could not init mouse.\n");
22 return 1;
23 }
24 if (!al_install_keyboard()) {
25 printf("Could not init keyboard.\n");
26 return 1;
27 }
28 display = al_create_display(300, 300);
29// display2 = al_create_display(300, 300);
30 al_set_window_title("Allegro 4.9.8 Test");
31 
32 al_get_keyboard_state(&key_state);
33 while (!al_key_down(&key_state, ALLEGRO_KEY_ESCAPE)) {
34 al_get_mouse_state(&mouse_state);
35 
36 al_rest(0.15);
37 al_get_keyboard_state(&key_state);
38 }
39 
40 return 0;
41}
42END_OF_MAIN()

This code crashes, but if I uncomment the lines for display2, the program runs fine.

Trent Gamblin
Member #261
April 2000
avatar

The program doesn't crash here for me (MinGW/Vista). Could you provide a backtrace or any other useful info you can get?

kenmasters1976
Member #8,794
July 2007

Sorry, I'll find out how to do a backtrace and post back.

I've tried compiling the program with the complete binary package in allegro5.org installed and it keeps crashing, so I think it might be a problem with my drivers or something.

[EDIT:] I don't know how to do a proper bakctrace. I've tried some simple instructions I found, but this is all I get:

Quote:

GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(no debugging symbols found)
(gdb) run
Starting program: C:\allegro.cc\Allegro5/Allegro5Test.exe
[New thread 1384.0xef8]
(no debugging symbols found)
(no debugging symbols found)
[New thread 1384.0x86c]
[New thread 1384.0x80]

Program received signal SIGSEGV, Segmentation fault.
0x6347589c in mouse_directx_get_state (ret_state=0x22fe20)
at C:\Users\trent\4.9.8\src\win\wmouse.c:1048
1048 C:\Users\trent\4.9.8\src\win\wmouse.c: No such file or directory.
in C:\Users\trent\4.9.8\src\win\wmouse.c
(gdb) backtrace
#0 0x6347589c in mouse_directx_get_state (ret_state=0x22fe20)
at C:\Users\trent\4.9.8\src\win\wmouse.c:1048
#1 0x6347589c in mouse_directx_get_state (ret_state=0x1)
at C:\Users\trent\4.9.8\src\win\wmouse.c:1048
Backtrace stopped: frame did not save the PC
(gdb) quit

On the other hand, the program doesn't crash if compiled with the 4.9.7 binary package.

[EDIT 2:] I built the debug lib on my machine 'cause it doesn't come with the binary package. Here's what I get now:

Quote:

GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(no debugging symbols found)
(gdb) run
Starting program: C:\allegro.cc\Allegro5/Allegro5Test.exe
[New thread 496.0x1d0]
(no debugging symbols found)
(no debugging symbols found)
[New thread 496.0x1e4]
[New thread 496.0x1e0]

Program received signal SIGSEGV, Segmentation fault.
0x625b4025 in mouse_directx_get_state (ret_state=0x22fe10)
at C:/allegro-4.9.8/src/win/wmouse.c:1048
1048 the_mouse.state.display = win_disp->is_mouse_on ? (void*)win_disp : NULL;
(gdb) backtrace
#0 0x625b4025 in mouse_directx_get_state (ret_state=0x22fe10)
at C:/allegro-4.9.8/src/win/wmouse.c:1048
#1 0x6259d5fe in al_get_mouse_state (ret_state=0x22fe10)
at C:/allegro-4.9.8/src/mousenu.c:250
#2 0x00401440 in _mangled_main ()
#3 0x625b4348 in _WinMain (_main=0x4012e0, hInst=0x400000, hPrev=0x0,
Cmd=0x241f1b "", nShow=10) at C:/allegro-4.9.8/src/win/wnewsys.c:136
#4 0x0040152d in WinMain@16 ()
#5 0x00401851 in main ()
(gdb) quit

And this is the content of the allegro.log file:

Quote:

ALLEGRO_SYSTEM_INTERFACE created.
al-winput INFO: Input thread started.
Render-to-texture: 1
al-wmouse INFO: mouse handler starts
faux_fullscreen=0
Normal window
BeginScene succeeded in create_device
Success
al-wmouse WARNING: mouse device not acquired or lost

I understand that the fault may be on my side, so I'm posting this just in case it's useful for the Allegro 5 devs.

Don Freeman
Member #5,110
October 2004
avatar

I am having the same issues with it (the mouse state) too using Visual Studio 2008 Pro on Vista. My other post is here. I have not tried to create another display to see if that helps, but I guess it can't hurt. The funny thing is, is that it doesn't crash every time...seems to be random. I can only guess something screwy in the mouse code.:-/ I'll try and take a look in the source to see if I can figure out what the hell is going on.:'(

Edit: It seems that the mouse driver gets confused as to what the current display is. If you add a call to: al_set_current_display, then at least so far...it doesn't crash. I am assuming this should solve your problem as well.:D I don't know exactly where or how to fix this in the allegro source, but I'm sure someone (Peter,Elias,Evert,etc) could find it...:D
Spoke too soon, I'm afraid. Maybe just creating another display and delete it after setting the current display would work.???

Edit2:
Yeah...that seems to work (at least after about 20 runs it hasn't crashed.::)). That is really weird. I am just lost in the source...I'll keep digging though.

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Milan Mimica
Member #3,877
September 2003
avatar

Don Freeman
Member #5,110
October 2004
avatar

Sorry, didn't notice that. It works perfectly now.:D

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Go to: