Hanging application
Onewing

I've mentioned it before, but it seems my programs freeze at will. I can't seem to figure out what's wrong and I'm not sure what code to post (if any). Nothing I do causes the freeze, it happens for a different reason every time across several of my allegro 4.2 games. I'm using Windows XP Professional Version 2002 Service Pack 2. Here's the event viewer application error:

[quote eventvwr]
Hanging application Toggles.exe, version 0.0.0.0, hang module hungapp, version 0.0.0.0, hang address 0x00000000.[/quote eventvwr]

Anybody have any ideas. I've got every thing ready for version 2.0 of Toggles and want to release it, but this err makes me hesitant and I've been holding it off (also because I'm trying to make an instructional video for it for youtube and it keeps freezing).

:'(

Kibiz0r

Can you try it on another computer?

gilles fetis

I also have the freeze sometimes on my current project (lisa emulator).
I'm using Win XP pro and win 98 with devc++ 4.9.9.2. The freeze happens on both plateforms (but is more frequent on XP).
While freezing, the window will correctly close if "Ctrl" "Alt" "End" is pressed. If the program has frozen once, it will always freeze if restarted (need to reboot).

Onewing
Quote:

Can you try it on another computer?

I've tried the different programs on my work computer to see how they'd run. They still freeze (although not nearly as often), but that's inclusive, because it was older versions of the program and might have been caused by an unrelated action. My work system has the exact same OS, just different specs (slower).

As I wrote this, I decided to check the eventvwr of my work computer. It seems to keep records back to March 13th. I noticed three "Application Hang" errors. One was for Toggles, one for explorer.exe and one was for codeblocks.exe (which I recently downloaded). Same generic error. :-/

Bump
I really am lost on this one. :-/

bamccaig

I'm sort of intermediate so my advice might not be very useful. :-[

Have you tried stepping through the program with a debugger to see where it hangs? Maybe there is an exception not handled or something hardware-related failing?

How long can you play before the hang-up? I would make sure that memory is being released properly and use exception handling where necessary. And always check for failed function calls, if you're not already.

???

Onewing
Quote:

Have you tried stepping through the program with a debugger to see where it hangs?

It could be one minute, it could be 30 minutes and it might not happen at all. I've sat around playing while running the debugger and of those few times, it didn't freeze.

I suppose I could write a function that logs which function was called and put that at the beginning of each function. I don't know, it's frustrating. Also, it didn't freeze when I was using several different profilers (when I was checking out different Window's profilers).

***!!!!!!!!!!!!!!!!!! UPDATE !!!!!!!!!!!!!!!!!!!!!***
Okay, something just happened that might be a big clue as to what's happening, maybe not. Read on, fellow good-doers.

I decided to open up a console window along side my program and output debug messages to it. In the main function that calls each object's update function, I put a call before and after, letting me know if an object completed or if stalled. I did this for the drawing as well.

Then, I saved and ran it. About 10 minutes into playing and the game freezes, but guess what, messages are still being relayed to the console window! The game itself is "Not Responding". I do a "pause" on the console to see what's still going (thinking everything is still going). Then, I notice I'm only seeing the drawing functions! There are no logs about anything being updated. You'd think there's something wrong with my timer logic, but would that cause windows to declare the program "Not Resonding" in the task manager?

I've got some cookies with your names on them... :-*

bamccaig

A program can only respond if it's listening for input. This is achieved with multi-threading usually to allow the interface to constantly respond. It slows down execution slightly, but it keeps the user in control which is desired. It sounds like your program is trapped in the drawing code...

I thought that Allegro handled threading automatically? I'm not sure... Anyway, it sounds like something is infinitely recursing or looping... Or something... ;) If the drawing code is happening and the game logic isn't then it sounds like the timer isn't configured property, apparently causing the game logic to never execute, and instead the drawing code is looping infinitely (and therefore not responding to you).

:-/:-/:-/:-/

Onewing

That sounds right, but in that case, the app itself is still valid, even if trapped in the drawing area. And if it's valid, that wouldn't cause Windows to flag it as "Not Responding," would it?

For reference, here's the basic timer logic of the game:

1...
2volatile int system_time;
3volatile int ticks;
4volatile int framerate;
5volatile int draw_ticks;
6PALETTE pal;
7COLOR_MAP trans_table;
8BITMAP *buffer;
9int gFade_Timer;
10int gTransparency;
11int startpos;
12int iTimer_Speed;
13INPUT gInput;
14bool iFrameRate;
15 
16 
17games GAME;
18 
19
20 
21void timer1(void)
22{
23 system_time++;
24}END_OF_FUNCTION(timer1);
25 
26void frametimer(void)
27{
28 framerate = draw_ticks;
29 draw_ticks = 0;
30}END_OF_FUNCTION(frametimer);
31...
32 
33void init()
34{
35 ...
36 // Install Time Handler
37 LOCK_VARIABLE(system_time);
38 LOCK_VARIABLE(ticks);
39 LOCK_VARIABLE(framerate);
40 LOCK_VARIABLE(draw_ticks);
41 LOCK_FUNCTION(timer1);
42 LOCK_FUNCTION(frametimer);
43 iTimer_Speed = GAME.configuration->clock_speed;
44 if(iTimer_Speed < 60) iTimer_Speed = 60;
45 install_int_ex(timer1, BPS_TO_TIMER(iTimer_Speed));
46 install_int_ex(frametimer, BPS_TO_TIMER(1));
47 ...
48}
49 
50...
51 
52void play_game()
53{
54 if(GAME.configuration->framerate == 1)
55 iFrameRate = true;
56 else
57 iFrameRate = false;
58 game_init();
59 
60
61 GAME.audio.add_to_playlist("./data/music/Right On!.ogg");
62 GAME.audio.add_to_playlist("./data/music/Toggle Me.ogg");
63 GAME.audio.set_loop();
64 //Title_Screen();
65 GAME.gHSC->get_local();
66
67 GAME.audio.stop();
68 while(!gInput.MAP(CANCEL,5) && !GAME.quit)
69 {
70 while(system_time)
71 {
72 system_time--;
73 ticks++;
74 game_update();
75 }
76
77 draw_ticks++;
78 game_draw();
79 if(system_time == 0) //Share the computer
80 rest(1);
81 
82 if(iFrameRate)
83 textprintf_ex(screen, font, 0, 0, -1, -1, "Framerate: %dfps", framerate);
84
85 }
86 GAME.audio.stop();
87
88 GAME.audio.breakdown();
89 game_shutdown();
90 
91}

bamccaig

I'm kinda new to Allegro... That looks slightly over my head. The only way I know how to do it is:

1#ifndef BEATS_PER_SECOND
2#define BEATS_PER_SECOND 60
3#endif
4 
5volatile bool gblnCloseButtonPressed = false;
6volatile int gintPendingFrames = 0;
7 
8void AddFrame(void)
9{
10 gintPendingFrames++;
11}
12END_OF_FUNCTION(AddFrame)
13 
14void CloseButtonPressed_Handler(void)
15{
16 gblnCloseButtonPressed = true;
17}
18END_OF_FUNCTION(CloseButtonPressed_Handler)
19 
20int main(int argc, char *argv[])
21{
22 // Initialize Allegro.
23 allegro_init();
24 
25 // Initialize Keyboard Routines.
26 install_keyboard();
27 
28 // Initialize Timer Routines.
29 install_timer();
30 
31 // Lock close button flag and function.
32 LOCK_VARIABLE(gblnCloseButtonHandler);
33 LOCK_FUNCTION();
34 
35 // Set close button handler.
36 set_close_button_callback(CloseButtonPressed_Handler);
37 
38 // Lock timing variable and function.
39 LOCK_VARIABLE(gintPendingFrames);
40 LOCK_FUNCTION(AddFrame);
41 
42 // Set Timer...
43 install_int_ex(AddFrame, BPS_TO_TIMER(BEATS_PER_SECOND));
44 
45 // Set Color Depth.
46 set_color_depth(16);
47 
48 // Set Graphics Mode.
49 set_gfx_mode(AUTODETECT_WINDOWED, 800, 600, 0, 0);
50 
51 // Main game loop...
52 while(!key[KEY_ESC] && !gblnCloseButtonPressed)
53 {
54 // Game logic loop -> timer dependant.
55 while(gintPendingFrames > 0)
56 {
57 // Game logic...
58 
59 gintPendingFrames--;
60 }
61 
62 // Drawing code...
63 }
64 
65 return 0;
66}
67END_OF_MAIN()

:-/:-/

Onewing

Argh.

I took piccolo's advice from my previous thread on this topic, did manage to find some major leaks, fixed them all, but the problem persists. At this point, I'm pretty sure it has nothing to do with my code. /cry

It's like the hardware interrupt timer function that consistently increases my system_time variable just doesn't interrupt anymore. I added a debug message that displays what the system_time is at the end of the game loop. When the game freezes, it constantly says it is 0.

Here's another thing. The console window displaying all the debug messages constantly is outputting debug messages. If the program is not frozen and I give focus to the console window, the messages stop as soon as I click it. However, if the program is frozen and I click the console window, the messages keep going until I hit the "Pause | Break" key. Very...odd.

Anyway, this might be my last post on the topic, due to my recent tomfoolery, since I have a post cap on my head of 5 posts per thread (that might just be in the Off-Topic forum though). I'll still give credits if I can...

[edit]
Update
Either I've found the mysterious problem, or I've done something else to fix it (or it still exists). I noticed a rogue dll file in the directory where I was testing the app. I moved the binary to another location without the dll and gave it a try. I played for 40 minutes without it ever freezing. Of course, that's inconclusive as to whether the problem is solved, but for now, I'm going to say that fixed it. ;)

Thread #590954. Printed from Allegro.cc