Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] Close button doesn't work when switching out of fullscreen

This thread is locked; no one can reply to it. rss feed Print
[A5] Close button doesn't work when switching out of fullscreen
Neil Roy
Member #2,229
April 2002
avatar

I am not certain if there is something I am missing, or if this is a bug with Allegro 5? I am using 5.1.11, all works fine (I am really loving it!). My game is in the final stretch, I am just bug testing it now to see where problems might exist. I easily swatted quite a few of them, but one.

I was testing out switching back and forth between different modes, from windowed, to full screen windowed and back, also windowed to regular full screen and back. When I click the close button in windowed mode, works no problem, triggers the event. BUT, if I switch to regular (non-windowed) fullscreen mode, then I switch back to windowed mode from it, the close button no longer responds. All other input works just fine. If I switch to<->from fullscreen Windowed mode, no problem, close button triggers. It's just fullscreen to windowed that stops it.

Otherwise my game runs perfectly fine. This, to me is a minor issue, but I just know SOMEONE that plays my game will report it as a problem. ;) Now, if you exit the game and rerun it, with windowed mode now the default when you restart the game, no problem, close button works again. So something gets disabled for that when fullscreen mode is enabled in Allegro.

If it's a bug, I'm reporting it now. If not, what can I do to reset this?

---
“I love you too.” - last words of Wanda Roy

torhu
Member #2,727
September 2002
avatar

Would be helpful if you had a test case for this, I think. It works with my game, but that uses 5.0.7. I'm on Windows 8.1 64-bit.

Neil Roy
Member #2,229
April 2002
avatar

The close button works under normal circumstances. But if your program is in fullscreen mode, then you switch to windowed mode while the game is running, then it won't work.

I'll see if I can whip up a simple program to demonstrate this. I am using Allegro 5.1.11 with Windows 7-64bit (the program is 32bit) compiled with MinGW 4.8.1 (Code::Blocks IDE).

I basically discovered this while bug testing my game, it's not something I probably would have ever noticed otherwise.

Edit: Okay, I just created a test program which does the bare minimum, it creates a fullscreen display, then destroys it and creates a windowed mode display and that closes okay, so I am a little confused as to why it would stop playing in my game. The event is simply not coming up, I wonder if I might need to re-initialize the event handler when I change the display. <shrug>

Edit2: Okay, solved the problem. The event queue is registered with the following...

al_register_event_source(event_queue, al_get_display_event_source(display));

So when the display is destroyed and re-initialized, I need to register the event queue again as well. I should probably be careful to destroy the event queue at the same time I destroy the display as well. nope, destroying the event queue crashes the program, so just re-registering the display is needed. Otherwise, when a new display is created without initializing the event queue again, the close button will stop working.

---
“I love you too.” - last words of Wanda Roy

Bruce Pascoe
Member #15,931
April 2015
avatar

Yes, each display has its own event source, so you have to re-register the new one to the queue. As for the segfault, I assume it's crashing because you didn't unregister the queue before destroying it? Just a guess.

Neil Roy
Member #2,229
April 2002
avatar

Yes, each display has its own event source, so you have to re-register the new one to the queue. As for the segfault, I assume it's crashing because you didn't unregister the queue before destroying it? Just a guess.

Ah, right! I forgot to unregister it, thanks, I'll add that in. Otherwise my game is complete. I just got done more bug testing, this was the last major bug there was (this and some other missing code to handle the close button on various screens).

Edit: That worked. I unregistered it. I realized I shouldn't be destroying the event_queue, but only unregistering the display before I destroy the display. I then register the display again with the event_queue after I recreate it. All is working smoothly with this anyhow, thanks. I've only done basic work with the event queue, being used to the old Allegro 4 state machine. So this has been a learning curve, getting used to remembering to do these sorts of things has been helpful.

---
“I love you too.” - last words of Wanda Roy

Bruce Pascoe
Member #15,931
April 2015
avatar

I think the crash specifically is a race condition: al_destroy_event_queue() automatically unregisters all event sources attached to it. If you destroy the display first, that source is no longer valid, so when Allegro goes to detach it, bam, segfault.

This is why it's always best to shutdown in the reverse order of initialization, even when it doesn't seem necessary. :)

SiegeLord
Member #7,827
October 2006
avatar

If you destroy the display first, that source is no longer valid, so when Allegro goes to detach it, bam, segfault.

If you destroy the display first, it'll detatch itself from the queue, so everything should be fine. The crash probably has a different source.

But yes, if you re-create the display, you'll want to re-register it with the event queue.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Bruce Pascoe
Member #15,931
April 2015
avatar

@SiegeLord:
Hm, you're right--in fact my shutdown code does just that:

al_destroy_display(g_display); g_display = NULL;
al_destroy_event_queue(g_events); g_events = NULL;

Destroying the display first. Odd, no idea what caused the crash then.

Of course the general advice of "shut down in reverse order" still applies to minimize issues.

Neil Roy
Member #2,229
April 2002
avatar

Yeah, I usually do shut down in reverse order. I don't even know why I tried to destroy the event queue when all I wanted to do was unregister the display. Brain must have frozen up at the time or something. ;)

But why it crashed, I am not certain, if everything said is true, than that is strange. But it works now and I am finally about done with that game, ;D... I want to move on to something else but I vowed not to start a new project until I finished this. :)

---
“I love you too.” - last words of Wanda Roy

Mark Oates
Member #1,146
March 2001
avatar

What's the game?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Neil Roy
Member #2,229
April 2002
avatar

Yet another Deluxe Pacman game. ;D... it was an idea about a remake I was interested in like... 6 years ago... and have fiddled around with on and off since then. I wanted to remake the original because it was started in the 1990s on... Allegro 2 I think, and updated since.

It's nothing fantastic, but it runs. My Deluxe Pacman 1 game still gets thousands of downloads a month from one website out there (lots of people in South America eat these sort of games up, so, there's a market for you people).

Anyhow, here's the download as it is now, compiled with Allegro 5.1.11, with level editor etc. Programmed with CB + MinGW 4.8.1 in pure C (2011 standard).

http://home.cogeco.ca/%7Edeluxe.pacman/zips/DPacman2_2015JUL04.zip

Edit: The display problems were mainly with going into the OPTIONS menu and changing the video mode, usually from FULLSCREEN to Windowed which lead to the close button not working. No big deal really, but now it works. Changes resolutions right away and saves that for the next time it is run. It has Windowed, Fullscreen-Windowed and Fullscreen modes.

---
“I love you too.” - last words of Wanda Roy

RPG Hacker
Member #12,492
January 2011
avatar

Can't start that game on my PC because "OpenAL32.dll" is missing. Don't know if this intended/known or not, but since the game uses an installer, anyways, it should probably also install OpenAL (and all other dependencies) on your system. I'm on Windows 8.1, btw.

The Level Editor works, though.

EDIT:
And is quite great, too. Love the automatic wall connecting, symmetric drawing and validating. Good job on that one! I'll eventually give the game a try, too, even if I have to install OpenAL (although I'd prefer not to do that if it's avoidable).

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Bruce Pascoe
Member #15,931
April 2015
avatar

OpenAL can be compiled statically, I've done it before. I think the included MSVC solution doesn't have a static config by default; you have to create one. You have to use 1.15 or earlier though, recent versions include an al_open_file() or something that clashes with Allegro's function of the same name.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Bruce Pascoe
Member #15,931
April 2015
avatar

For what it's worth you're probably better off compiling out the OpenAL support from Allegro anyway. Allegro doesn't use any of the advanced 3D effects so it's honestly just bloat. I've stopped including it myself.

Neil Roy
Member #2,229
April 2002
avatar

Hmmm, I don't get that problem on my system and I don't have the dll in my path, or at least I didn't think I did. Obviously I do! Can I recompile the game without the need for it? It's strange this is the first time anyone has even told me about that. Could be just 5.1.11 it is missing as before I used 5.0.8.

And is quite great, too. Love the automatic wall connecting, symmetric drawing and validating. Good job on that one! I'll eventually give the game a try, too, even if I have to install OpenAL (although I'd prefer not to do that if it's avoidable).

Thanks, the level editor is the first thing I create when I start making a game and I wanted to make certain that if a level was loaded, there would be nothing missing and no potential errors so the validation checks for everything. If you have a spot to wrap around on one side, but not the other, it will point it out to you. If you have pills in spots on the map that the pacman cannot get to, it will mark the areas that are blocked off (I used the ghost path finding function to actually test this, which works nicely) etc... you name it, it will probably test for it. Unvalidated maps will not load into the game. So it's a nice idea I felt. I actually got the idea for drawing a map like that (rather than a piece at a time) from SimCity 2000! The way you draw your roads, if you ever played it you will see how it autoconnects roads up, so I thought, hey, why can't I use that for lines, and of course, most levels I like symmetrical, so no sense in repeating drawing when you can have the editor do it for you.

There's still some things I want to change in it, like the ability to just put down ONE piece and not auto-connect it, for certain map ideas. Plus I am working lately on making the level editor remember the name of the level file you loaded so when you save it, THAT is the default name.

I guess the reason why the level editor works is because I have no sound effects for it. I was going to but just never got around to it.

Edit: Okay, I recompiled the game, fixed that problem in the level editor so now it remembers the filename for the level you load. The installer now installs the OpenAL dll into the game's main folder. So it SHOULD work now (famous last words)...

http://home.cogeco.ca/%7Edeluxe.pacman/zips/DPacman2_2015JUL08.zip

---
“I love you too.” - last words of Wanda Roy

Bruce Pascoe
Member #15,931
April 2015
avatar

If you're compiling Allegro yourself, you can compile out the OpenAL dependency via disabling CMake flag WANT_OPENAL. I believe the official 5.1.11 binaries were compiled without it already though... at least that's what I remember SiegeLord saying.

RPG Hacker
Member #12,492
January 2011
avatar

The error with OpenAL is gone in this version, but now it can't find "libgcc_s_dw2-1.dll". I'm at my work computer, so I don't have GCC installed here (and even on my private computer, I think, I don't have, since I'm using the Visual Studio compiler for Allegro). I guess the GCC libs probably weren't linked statically correctly. I think I had this kind of issue before when working with Allegro and actually using GCC, but I'm not sure how I solved it back then (or if I solved it at all).

EDIT:
One thing that could really enhance the editor would be an undo command. When using it, it should basically undo everything that happened between the last mouse key press and the last mouse key release. I've had it happen various times now that I had to switch back and forth between different objects because my sensible mouse made me draw something I didn't want to.

Neil Roy
Member #2,229
April 2002
avatar

Yup, I seen that error posting on my facebook page <sigh>, something in this library needs that DLL as in the past I always statically link without problems.

Anyhow, I recompiled it AGAIN... can't get rid of that dependency for the libgcc dll, so I am including it as well! I am starting to think I should say screw it with regards to statically linking and just include all DLLs needed instead! heheh... this time before packaging it up yet again, I removed my MINGW\bin from my path and tested it and there were no missing DLLs now. I had to include OpenAL and the libgcc dlls. I tried compiling this project without OpenAL but it needs it for some reason.

So... without further adieu, the lastest version, this time, with no problems! ;D (famous last words)

http://home.cogeco.ca/%7Edeluxe.pacman/zips/DPacman2_2015JUL09.zip

Yeah, an UNDO was one of those things I have been meaning to add. Shouldn't be too hard to implement. Just need to keep a copy of the level between mouse clicks as you pointed out.

Oh yes, and the normal solution for statically linking GCC is to use either -static (which always worked for me before) or -static-libgcc, but that doesn't work anymore, I am assuming it has something to do with the way the library was compiled. I didn't build this, I am using the Allegro 5.1.11 prebuilt provided as I always seem to have trouble compiling Allegro 5, though I may give it another go as I prefer that (I used to build Allegro 4 all the time with no problems, but all these dependencies...)

I don't know if you know this, but you left click to draw, but you can also right click to erase a tile and it will adjust the surrounding pieces automatically. Also, the mouse wheel changes the background tile (in case you didn't read the manual ;) )

---
“I love you too.” - last words of Wanda Roy

RPG Hacker
Member #12,492
January 2011
avatar

YAY, IT'S WORKING NOW! :D

Although it glitched quite a bit on my first attempt. When starting the game - it automatically launched in fullscreen mode - the game forced intself into the background/minimized itself. When going back into the game, it for some reason ran really, really slow (as in, 1 frame every few seconds). I switched out of the game and back in again (with Alt + Tab) and for some reason the game now was completely black aside from the mouse cursor (the sound was already playing, though). Switched back and forth a few times, but the game stayed black. I decided to close the game and restart it and finally it worked for me and ran smoothly (this time it didn't minimize itself on startup). I don't know, what was going on there, but I guess I can just switch into window mode to prevent this problem.

Neil Roy said:

I don't know if you know this, but you left click to draw, but you can also right click to erase a tile and it will adjust the surrounding pieces automatically.

Yeah, I figured this out, because naturally, at some point I asked myself how to remove pieces again and just tried the right mouse button. Didn't know about the mouse wheel, though. Going to give this a try.

EDIT:
Apparently the slowdown in the game starts whenever it minimizes itself during startup. It just happened again. I don't know, why it keeps minimizing on startup, but I'd guess that it's not the game's fault, but my computer's. More accurately, I think it might be the fault of BlueStacks App Player. If I remember correctly, I've experienced it forcing itself into the foreground quite a few times when trying to start other games in fullscreen mode. With said other games it never caused the slowdown, though. Those games usually worked fine after switching back into them.

EDIT:
Also, you confused fullscreen and fullscreen window in the options. The game on my PC actually starts in fullscreen mode, but is set to fullscreen window in the options. This may be one of the reasons why it glitched up.

Neil Roy
Member #2,229
April 2002
avatar

I definitely have no problems with minimizing, so that is definitely on your end. You can manually edit the INI file to change settings after your first run.

As for fullscreen and fullscreen window being reversed... <looks at code> Yup! ;D, I don't know how I missed that! Just a switch/case statement mixed around. Easy fix <sigh> just when I thought I caught them all! ;)

Normally I run the game in Windowed mode when coding and both fullscreen modes look alike and run with no problems for me so I never noticed. :-/

I don't know what to say about that program forcing itself into the foreground and causing a minimize, I don't minimize my game ever so... <shrug>

The reversed fullscreen/fullscreen window wouldn't cause a glitch though. It shouldn't matter except that if you click one or the other you get the wrong one in options. But the mode is still set properly in either case. All the options does is set a number (mode 0, 1 or 2) then some code in other parts changes the display based on that... but nothing that would cause a glitch at all. Absolutely not.

EDIT:

Fixed that anyhow. Game starts in fullscreen mode by default the first time it is run. The options menu should correctly reflect which you have on now and properly switch between the two. I may have to download that program you use and see if I can duplicate that problem you have and solve it somehow. But honestly, if I had a program do that, I would switch programs to something else or see if it had an option to not force itself into the foreground, because that would be annoying as hell.

http://home.cogeco.ca/%7Edeluxe.pacman/zips/DPacman2_2015JUL10.zip

---
“I love you too.” - last words of Wanda Roy

RPG Hacker
Member #12,492
January 2011
avatar

As I tried to explain, the game was pushed into the background right when starting up (that is, the monitor switched into fullscreen mode for a brief moment and then right back to the desktop). Maybe the time at which this happens is actually important. As in: Maybe the glitch doesn't occur if you switch to another task after the game has already started properly. Can't tell for sure, though, this is just speculation. It might just happen on my computer after all. In any case, it's not a big deal to begin with and I am probably the only person to ever experience this glitch, anyways.

Neil Roy said:

The reversed fullscreen/fullscreen window wouldn't cause a glitch though.

Oh, I think I didn't explain what I meant well enough. What I meant was that these glitches were probably caused by the game running in regular fullscreen mode instead of in a fullscreen window. Fullscreen mode is actually known for its ability to cause trouble in some games on some PCs (thanks to losing contexts, switching graphics cards settings and stuff like that). That is why, generally speaking, fullscreen windows are the preferred way of handling fullscreen applications nowadays. Maybe you should just make fullscreen window the default option, I can imagine that to already solve the problem. Then again, fullscreen windows might have their own problems, I don't have enough experience with that.

Neil Roy
Member #2,229
April 2002
avatar

I would actually prefer to make a fullscreen window the default, but I am uncertain if that might lead to problems on certain systems. The reason why I chose regular fullscreen mode is due to the fact that it has been around a while, I figured most systems should handle it okay.

Of course, the alternative is default to windowed mode, but I really would prefer if it was one of the fullscreen modes, I actually do prefer the fullscreen window as it is just plain easier and faster to alt+tab between programs.

If there would be less issues with it, I would gladly switch to it as a default.

---
“I love you too.” - last words of Wanda Roy

Go to: