Skip to content

Commit c2edbda

Browse files
authored
Core: fixing audio onComplete(#673)
1 parent 2459919 commit c2edbda

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

librtt/Rtt_PlatformNotifier.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ PlatformNotifier::ScheduleDispatch( VirtualEvent *e )
6363
}
6464
}
6565

66+
void
67+
PlatformNotifier::ScheduleDispatch( VirtualEvent *e, int ref )
68+
{
69+
if ( Rtt_VERIFY( e ) )
70+
{
71+
bool scheduled = false;
72+
Rtt_ASSERT( LUA_NOREF != ref && LUA_REFNIL != ref );
73+
74+
lua_State *L = GetLuaState();
75+
Rtt_ASSERT( L );
76+
if ( L )
77+
{
78+
Runtime *runtime = LuaContext::GetRuntime( L );
79+
80+
PlatformNotifierTask *task = Rtt_NEW( runtime->Allocator(), PlatformNotifierTask( * this, e ) );
81+
82+
task->SetReference( ref );
83+
84+
runtime->GetScheduler().Append( task );
85+
86+
scheduled = true;
87+
}
88+
89+
// In case of error, we need to delete the event
90+
if ( ! Rtt_VERIFY( scheduled ) )
91+
{
92+
Rtt_DELETE( e );
93+
}
94+
}
95+
}
96+
6697
bool
6798
PlatformNotifier::HasListener() const
6899
{
@@ -163,7 +194,8 @@ PlatformNotifier::RawSetListenerRef(int ref)
163194
PlatformNotifierTask::PlatformNotifierTask( PlatformNotifier& notifier, VirtualEvent *e )
164195
: Super(),
165196
fNotifier( notifier ),
166-
fEvent( e )
197+
fEvent( e ),
198+
fLuaRef( LUA_NOREF )
167199
{
168200
Rtt_ASSERT( e );
169201
}
@@ -176,7 +208,21 @@ PlatformNotifierTask::~PlatformNotifierTask()
176208
void
177209
PlatformNotifierTask::operator()( Scheduler & sender )
178210
{
211+
int oldRef = fNotifier.GetListenerRef();
212+
213+
if ( LUA_NOREF != fLuaRef )
214+
{
215+
fNotifier.RawSetListenerRef( fLuaRef );
216+
}
217+
179218
fNotifier.CallListener( fEvent->Name(), *fEvent );
219+
220+
if ( LUA_NOREF != fLuaRef )
221+
{
222+
fNotifier.RawSetListenerRef( oldRef );
223+
224+
fLuaRef = LUA_NOREF;
225+
}
180226
}
181227

182228
// ----------------------------------------------------------------------------

librtt/Rtt_PlatformNotifier.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class PlatformNotifier
4545
public:
4646
// Caller must release ownership of event (it will be disposed of by the runtime)
4747
void ScheduleDispatch( VirtualEvent *e );
48+
void ScheduleDispatch( VirtualEvent *e, int ref );
4849

4950
public:
5051
void SetListenerRef( int index );
@@ -86,6 +87,9 @@ class PlatformNotifierTask : public Task
8687
protected:
8788
PlatformNotifierTask( PlatformNotifier& notifier, VirtualEvent *e );
8889

90+
protected:
91+
void SetReference( int ref ) { fLuaRef = ref; }
92+
8993
public:
9094
~PlatformNotifierTask();
9195

@@ -95,6 +99,7 @@ class PlatformNotifierTask : public Task
9599
protected:
96100
PlatformNotifier& fNotifier;
97101
VirtualEvent *fEvent;
102+
int fLuaRef;
98103

99104
friend class PlatformNotifier;
100105
};

librtt/Rtt_PlatformOpenALPlayer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,7 @@ PlatformOpenALPlayer::NotificationCallback( int which_channel, unsigned int al_s
11241124
// Bug 5724: In addition to setting all the callback properties, we pass the notifier in to transfer ownership.
11251125
// We expect when the event is fired and deleted, it will also delete the notifier with it.
11261126
e->SetProperties( which_channel, al_source, almixer_data, finished_naturally );//notifier );
1127-
notifier->RawSetListenerRef( callback );
1128-
notifier->ScheduleDispatch( e );
1129-
notifier->RawSetListenerRef( LUA_NOREF );
1127+
notifier->ScheduleDispatch( e, callback );
11301128
}
11311129
}/*
11321130
else

0 commit comments

Comments
 (0)