mirror of
https://github.com/storytold/UE4-OSC.git
synced 2026-10-09 00:09:43 +00:00
bugfix: listener stops randomly
detail: - task is running - an OSC message is received, _pendingMessages is not yet empty - task finishes before the OSC message is added to _pendingMessages - no other task can be executed (_pendingMessages is never empty)
This commit is contained in:
@@ -165,8 +165,6 @@ static void SendBundle(TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct
|
||||
|
||||
void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
|
||||
{
|
||||
const auto wasEmpty = _pendingMessages.IsEmpty();
|
||||
|
||||
const osc::ReceivedPacket packet((const char *)data->GetData(), data->Num());
|
||||
if(packet.State() != osc::SUCCESS)
|
||||
{
|
||||
@@ -184,9 +182,9 @@ void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
|
||||
}
|
||||
|
||||
// Set a single callback in the main thread per frame.
|
||||
if(wasEmpty && !_pendingMessages.IsEmpty())
|
||||
if(!_pendingMessages.IsEmpty() && !_runPendingMessagesTask)
|
||||
{
|
||||
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
|
||||
_runPendingMessagesTask = FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
|
||||
FSimpleDelegateGraphTask::FDelegate::CreateUObject(this, &UOscDispatcher::CallbackMainThread),
|
||||
TStatId(),
|
||||
nullptr,
|
||||
@@ -205,6 +203,11 @@ void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
|
||||
|
||||
void UOscDispatcher::CallbackMainThread()
|
||||
{
|
||||
// Release before dequeue.
|
||||
// If it was released after dequeue, when a message arrives after the while
|
||||
// loop and before the release, it would not be processed.
|
||||
_runPendingMessagesTask.SafeRelease();
|
||||
|
||||
FScopeLock ScopeLock(&_receiversMutex);
|
||||
|
||||
std::pair<FName, TArray<FOscDataElemStruct>> message;
|
||||
|
||||
@@ -43,13 +43,14 @@ private:
|
||||
void CallbackMainThread();
|
||||
|
||||
void BeginDestroy() override;
|
||||
|
||||
|
||||
private:
|
||||
TArray<IOscReceiverInterface *> _receivers;
|
||||
std::pair<FIPv4Address, uint32_t> _listening;
|
||||
FSocket * _socket;
|
||||
FUdpSocketReceiver * _socketReceiver;
|
||||
TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> _pendingMessages;
|
||||
FGraphEventRef _runPendingMessagesTask;
|
||||
|
||||
/// Protects _receivers
|
||||
FCriticalSection _receiversMutex;
|
||||
|
||||
Reference in New Issue
Block a user