Re: [AD] al_stop/al_uninstall_timer later fails

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Tue, April 20, 2010 6:37 pm, Peter Wang said:
> On 21 April 2010 08:15, Trent Gamblin <trent@xxxxxxxxxx> wrote:
>> With my recent change to the AQueue driver, I noticed that when I manually call
>> al_stop_timer and then al_uninstall_timer on a timer that was running, during
>> al_uninstall_system it tries to destruct that timer again, resulting in a crash. Any
>> more info you need I'd be happy to provide.
>
> I can't reproduce it with ex_timer.

It looks like it's an intermittent error, and happens sometimes whether or not
the timer is uninstalled.

I get the following:

Assertion failed: (found), function _al_unregister_destructor, file
/Users/trent/4.9/iphone-xcode/../src/dtor.c, line 178.

Running ex_stream_file with the AQueue driver (on iPhone).

It doesn't happen every time, in fact out of 4 tries right now it happened once.

It broke from revision 13288 to present (in aqueue.m), but I don't see the error. Is
everything I'm doing thread safe? I've attached the difference for convenience:


Index: aqueue.m
===================================================================
--- aqueue.m	(revision 13288)
+++ aqueue.m	(working copy)
@@ -32,6 +32,8 @@
 #import <AudioToolbox/AudioQueue.h>

 #define THREAD_BEGIN NSAutoreleasePool *___p = [[NSAutoreleasePool alloc] init];
+#define THREAD_DRAIN [___p drain];
+#define THREAD_RECREATE ___p = [[NSAutoreleasePool alloc] init];
 #define THREAD_END [___p release];


@@ -207,6 +209,13 @@
 {
    #ifdef ALLEGRO_IPHONE
    THREAD_BEGIN
+   /* We need to periodically drain and recreate the autorelease pool
+    * so it doesn't fill up memory.
+    */
+   ALLEGRO_TIMER *drain_timer = al_install_timer(30);
+   ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
+   al_register_event_source(event_queue, al_get_timer_event_source(drain_timer));
+   al_start_timer(drain_timer);
    #endif

    ALLEGRO_VOICE *voice = in_data;
@@ -279,9 +288,21 @@
          0.05,
          false
       );
+      #ifdef ALLEGRO_IPHONE
+      if (!al_event_queue_is_empty(event_queue)) {
+         ALLEGRO_EVENT event;
+	 al_get_next_event(event_queue, &event);
+	 if (event.type == ALLEGRO_EVENT_TIMER && event.timer.source == drain_timer) {
+	 	THREAD_DRAIN
+		THREAD_RECREATE
+	 }
+      }
+      #endif
    } while (playing);

    #ifdef ALLEGRO_IPHONE
+   al_destroy_event_queue(event_queue);
+   al_uninstall_timer(drain_timer);
    THREAD_END
    #endif


Trent :{)>




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/