Hi forum!
First I want to thank Edgar Reynaldo and Neil Roy, they help me with my last and solved question. https://www.allegro.cc/forums/thread/617247
But a new problem rised, when timer and video are together, Edgar Reynaldo gave me a piece of code but I didnt understand too much, I tried some times but can not run it fine.
So, I write this code to check my solution without copy & paste, it plays the video but when I press ESC (to finish the execution)it give me a Windows error:
"las.exe has stopped working.
A problem caused the program to stop working correctly. Windows will close the program and notify you if solution is available."
I searched in the forum, but I couldn't find a solution, ohhh and it message doesnt appear when I close the console.
Note: playvideo1 in the finished program must be false, and only when the student press a button with the mouse it must be true and then start video.
If the size of video is large it gives some glitches, but in this projects isn't a problem.
If somebody find the problem, please help me.
Try executing al_destroy_display(display); last. I am wondering if that might cause problems when you destroy it before you close the video or destroy the bitmaps?
As a rule of thumb, I destroy these things in the reverse order that I created them in, to be safe.
I would also check to see if your display variable is valid immediately after you create display and then exit(1) if it fails rather than waiting until later on to check it. I also note that you don't exit if it fails, so that will definitely cause a problem if creating it fails and then you go to exit normally, your program will try and destroy the display when none was created.
Always check for errors right away anyhow and exit if they fail with an error message, destroying anything that was created before you exit.
Are you using Visual Studio? If so, it's super easy to just turn on the debugger, place a breakpoint before the end, and "step through" the code until it blows up and you'll know the exact line it blew up.
Heck, even without the breakpoint, Visual Studio should still tell you the line of code responsible if you just run it with Debug (Control-F5?) instead of normal mode.
Thanks for reply, I tried some solutions, and change a lot of settings and this code works, doesn't give error BUT never return 0, unless if I comment al_close_video.
I use CodeBlocks so there are 2 logs, the first with no error and return 0, and the second never return 0 and no message error either, as we can see "DirectSound closed" disappeared.
My question is: is it so important al_close_video? can I fix it?
Both without message error
allegro.log (1) Return 0
d3d D E:\LIBS\LIBS71Build\allegro\src\win\d3d_bmp.cpp:539 _al_d3d_sync_bitmap [ 2.16498] _al_d3d_sync_bitmap (system) ref count == 1
d3d D E:\LIBS\LIBS71Build\allegro\src\win\d3d_bmp.cpp:545 _al_d3d_sync_bitmap [ 2.16501] _al_d3d_sync_bitmap (video) ref count == 1
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.30824] removed dtor for timer 01FB6140
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.30830] removed dtor for queue 01FB4248
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.30832] removed dtor for sub_bitmap 01FBBB98
video D E:\LIBS\LIBS71Build\allegro\addons\video\ogv.c:1104 decode_thread_func [ 3.31926] End decode loop.
audio W E:\LIBS\LIBS71Build\allegro\addons\audio\kcm_stream.c:641 _al_kcm_refill_stream [ 3.42019] Out of buffers
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.42351] removed dtor for timer 01FB5C70
video D E:\LIBS\LIBS71Build\allegro\addons\video\ogv.c:1113 decode_thread_func [ 3.42354] Thread exit.
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.42368] removed dtor for queue 0207E1E0
video D E:\LIBS\LIBS71Build\allegro\addons\video\ogv.c:252 free_stream [ 3.42375] Clean up Theora.
video D E:\LIBS\LIBS71Build\allegro\addons\video\ogv.c:268 free_stream [ 3.42386] Clean up Vorbis.
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.42397] removed dtor for bitmap 02075E18
d3d I E:\LIBS\LIBS71Build\allegro\src\win\d3d_disp.cpp:901 d3d_destroy_display [ 3.42415] destroying display 01FB2E20 (current 00000000)
d3d D E:\LIBS\LIBS71Build\allegro\src\win\d3d_disp.cpp:885 d3d_destroy_display_internals [ 3.42653] waiting for display 01FB2E20's thread to end
d3d W E:\LIBS\LIBS71Build\allegro\src\win\d3d_disp.cpp:595 d3d_destroy_device [ 3.43304] d3d_destroy_device: ref count not 0
d3d I E:\LIBS\LIBS71Build\allegro\src\win\d3d_disp.cpp:1550 d3d_display_thread_proc [ 3.43709] d3d display thread exits
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.43964] removed dtor for sample_instance 0003DF90
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.43966] removed dtor for mixer 0003DC60
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:513 _dsound_stop_voice [ 3.43967] Stopping voice
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:530 _dsound_stop_voice [ 3.43968] Joining thread
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:536 _dsound_stop_voice [ 3.44340] Joined thread
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:538 _dsound_stop_voice [ 3.44342] Destroying thread
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:540 _dsound_stop_voice [ 3.44343] Thread destroyed
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:547 _dsound_stop_voice [ 3.44344] Releasing buffer
audio-dsound I E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:551 _dsound_stop_voice [ 3.44345] Voice stopped
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.44348] removed dtor for voice 0003D788
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:365 _dsound_deallocate_voice [ 3.44349] Deallocating voice
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:370 _dsound_deallocate_voice [ 3.44350] Deallocated voice
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:281 _dsound_close [ 3.44352] Releasing device
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:283 _dsound_close [ 3.45713] Released device
audio-dsound I E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:284 _dsound_close [ 3.45716] DirectSound closed
__________________________________________________________________________________
allegro.log (2) never return 0
d3d D E:\LIBS\LIBS71Build\allegro\src\win\d3d_bmp.cpp:539 _al_d3d_sync_bitmap [ 3.35485] _al_d3d_sync_bitmap (system) ref count == 1
d3d D E:\LIBS\LIBS71Build\allegro\src\win\d3d_bmp.cpp:545 _al_d3d_sync_bitmap [ 3.43250] _al_d3d_sync_bitmap (video) ref count == 1
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.44549] removed dtor for queue 02066440
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.44553] removed dtor for timer 020665B0
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.44555] removed dtor for sub_bitmap 02068900
d3d I E:\LIBS\LIBS71Build\allegro\src\win\d3d_disp.cpp:901 d3d_destroy_display [ 3.44556] destroying display 0205F5F0 (current 00000000)
bitmap D E:\LIBS\LIBS71Build\allegro\src\bitmap_type.c:308 _al_convert_to_memory_bitmap [ 3.44850] converting display bitmap 020756D0 to memory bitmap
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:196 _al_register_destructor [ 3.44855] added dtor for bitmap 02066528, func 0040231F
d3d D E:\LIBS\LIBS71Build\allegro\src\win\d3d_bmp.cpp:539 _al_d3d_sync_bitmap [ 3.44858] _al_d3d_sync_bitmap (system) ref count == 1
d3d D E:\LIBS\LIBS71Build\allegro\src\win\d3d_bmp.cpp:545 _al_d3d_sync_bitmap [ 3.44859] _al_d3d_sync_bitmap (video) ref count == 1
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.45198] removed dtor for bitmap 02066528
d3d D E:\LIBS\LIBS71Build\allegro\src\win\d3d_disp.cpp:885 d3d_destroy_display_internals [ 3.45249] waiting for display 0205F5F0's thread to end
d3d W E:\LIBS\LIBS71Build\allegro\src\win\d3d_disp.cpp:595 d3d_destroy_device [ 3.45608] d3d_destroy_device: ref count not 0
d3d I E:\LIBS\LIBS71Build\allegro\src\win\d3d_disp.cpp:1550 d3d_display_thread_proc [ 3.46466] d3d display thread exits
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.46592] removed dtor for sample_instance 02051B88
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.46595] removed dtor for mixer 020516F0
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:513 _dsound_stop_voice [ 3.46596] Stopping voice
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:530 _dsound_stop_voice [ 3.46597] Joining thread
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:536 _dsound_stop_voice [ 3.47589] Joined thread
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:538 _dsound_stop_voice [ 3.47591] Destroying thread
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:540 _dsound_stop_voice [ 3.47593] Thread destroyed
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:547 _dsound_stop_voice [ 3.47593] Releasing buffer
audio-dsound I E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:551 _dsound_stop_voice [ 3.47594] Voice stopped
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.47596] removed dtor for voice 003FEE98
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:365 _dsound_deallocate_voice [ 3.47598] Deallocating voice
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:370 _dsound_deallocate_voice [ 3.47599] Deallocated voice
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:281 _dsound_close [ 3.47601] Releasing device
audio-dsound D E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:283 _dsound_close [ 3.54388] Released device
audio-dsound I E:\LIBS\LIBS71Build\allegro\addons\audio\dsound.cpp:284 _dsound_close [ 3.54391] DirectSound closed
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:116 _al_run_destructors [ 3.54392] calling dtor for timer 06D9F748, func 0042A6AD
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.54393] removed dtor for timer 06D9F748
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:116 _al_run_destructors [ 3.54394] calling dtor for queue 06D8F278, func 0042065F
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.54395] removed dtor for queue 06D8F278
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:116 _al_run_destructors [ 3.54397] calling dtor for bitmap 020756D0, func 0040231F
dtor D E:\LIBS\LIBS71Build\allegro\src\dtor.c:227 _al_unregister_destructor [ 3.54398] removed dtor for bitmap 020756D0
It's a good rule of thumb to destroy everything you create, and in the reverse order.
That said,
All you really need to do is close the video and shutdown allegro. Note, most of this is done for you automatically. al_uninstall_system is usually registered with atexit by al_init. Which means you don't need to call anything. Except al_close_video.
/// end main loop al_close_video(video); al_uninstall_system();/// mostly optional if you called al_init /// al_close_video(video);/// Would be bad, as allegro's vtable has been destroyed return 0; } /// Beware! Global destructors run here!!! (C++ warning)
EDIT
Updated code a little to be more clear on what is going on.
Hi! I solved the problem adding bitmap=NULL after somebody closes the windows or when the ESC buttom is pressed.
As you may have read, there was a log that worked, and that is rare, because one program give the same output for the same input; so, why some times did the program work? that smelled like pointer trouble.
So the program works fine now, thanks all for your help!
Don't destroy the 'bitmap' that al_get_video_frame returns. Allegro owns it.
Why split render and redraw into two separate clauses? They should really be the same thing.
You don't need to 'rest' after displaying the bitmap. Your timer event tells you when to redraw. Did ALLEGRO_EVENT_VIDEO_FRAME_SHOW not work for you?
Also, I hate to tell you, but allegro can save .bmp files directly from an ALLEGRO_BITMAP*.
Hi! I'll re-write all the code, so, after follow some adviced from Reynaldo now I can play the full video.
I don´t understand what is ALLEGRO_EVENT_VIDEO_FRAME_SHOW, and how can help me yet, I´ll seek more info.
The bitmap I save is one screenshot I make BEFORE the display (and that part of code I didnt show it). I searched something similar in Allegro-lib but I couldnt find it.
Oh, in that case carry on. Taking a screenshot is only possible with native code. But if you have an ALLEGRO_BITMAP*, you can save it as an image file, based on the extension.