mirror of
https://github.com/storytold/UE4-OSC.git
synced 2026-10-09 00:09:43 +00:00
bugfix: listener stops randomly (2)
detail: - _runPendingMessagesTask is assigned after the task has started, then - _runPendingMessagesTask.SafeRelease() has no visible effect, then - _runPendingMessagesTask is true for ever
This commit is contained in:
@@ -9,7 +9,8 @@ UOscDispatcher::UOscDispatcher()
|
|||||||
: _listening(FIPv4Address(0), 0),
|
: _listening(FIPv4Address(0), 0),
|
||||||
_socket(nullptr),
|
_socket(nullptr),
|
||||||
_socketReceiver(nullptr),
|
_socketReceiver(nullptr),
|
||||||
_pendingMessages(1024) // arbitrary max message count per frame
|
_pendingMessages(1024), // arbitrary max message count per frame
|
||||||
|
_taskSpawned(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,9 +183,10 @@ void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set a single callback in the main thread per frame.
|
// Set a single callback in the main thread per frame.
|
||||||
if(!_pendingMessages.IsEmpty() && !_runPendingMessagesTask)
|
if(!_pendingMessages.IsEmpty() && !FPlatformAtomics::InterlockedCompareExchange(&_taskSpawned, 1, 0))
|
||||||
{
|
{
|
||||||
_runPendingMessagesTask = FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
|
check(_taskSpawned == 1);
|
||||||
|
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
|
||||||
FSimpleDelegateGraphTask::FDelegate::CreateUObject(this, &UOscDispatcher::CallbackMainThread),
|
FSimpleDelegateGraphTask::FDelegate::CreateUObject(this, &UOscDispatcher::CallbackMainThread),
|
||||||
TStatId(),
|
TStatId(),
|
||||||
nullptr,
|
nullptr,
|
||||||
@@ -206,7 +208,8 @@ void UOscDispatcher::CallbackMainThread()
|
|||||||
// Release before dequeue.
|
// Release before dequeue.
|
||||||
// If it was released after dequeue, when a message arrives after the while
|
// If it was released after dequeue, when a message arrives after the while
|
||||||
// loop and before the release, it would not be processed.
|
// loop and before the release, it would not be processed.
|
||||||
_runPendingMessagesTask.SafeRelease();
|
check(_taskSpawned == 1);
|
||||||
|
FPlatformAtomics::InterlockedCompareExchange(&_taskSpawned, 0, 1);
|
||||||
|
|
||||||
FScopeLock ScopeLock(&_receiversMutex);
|
FScopeLock ScopeLock(&_receiversMutex);
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ private:
|
|||||||
FSocket * _socket;
|
FSocket * _socket;
|
||||||
FUdpSocketReceiver * _socketReceiver;
|
FUdpSocketReceiver * _socketReceiver;
|
||||||
TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> _pendingMessages;
|
TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> _pendingMessages;
|
||||||
FGraphEventRef _runPendingMessagesTask;
|
int32 _taskSpawned;
|
||||||
|
|
||||||
/// Protects _receivers
|
/// Protects _receivers
|
||||||
FCriticalSection _receiversMutex;
|
FCriticalSection _receiversMutex;
|
||||||
|
|||||||
Reference in New Issue
Block a user