Skip to content

Commit

Permalink
fix potential sort order bug #40
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Oct 16, 2021
1 parent 268882a commit 360fd96
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
Binary file modified Assets/uWindowCapture/Plugins/x86/uWindowCapture.dll
Binary file not shown.
Binary file modified Assets/uWindowCapture/Plugins/x86_64/uWindowCapture.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions Assets/uWindowCapture/Scripts/UwcLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static class Lib
private static extern IntPtr GetMessages_Internal();
[DllImport(name, EntryPoint = "UwcClearMessages")]
private static extern void ClearMessages();
[DllImport(name, EntryPoint = "UwcExcludeRemovedWindowEvents")]
private static extern void ExcludeRemovedWindowEvents();
[DllImport(name, EntryPoint = "UwcCheckWindowExistence")]
public static extern bool CheckWindowExistence(int id);
[DllImport(name, EntryPoint = "UwcGetWindowHandle")]
Expand Down Expand Up @@ -229,6 +231,8 @@ public static class Lib

public static Message[] GetMessages()
{
ExcludeRemovedWindowEvents();

var count = GetMessageCount();
var messages = new Message[count];

Expand Down
6 changes: 6 additions & 0 deletions Plugins/uWindowCapture/uWindowCapture/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ extern "C"
return MessageManager::Get().GetHeadPointer();
}

UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UwcExcludeRemovedWindowEvents()
{
if (MessageManager::IsNull()) return;
MessageManager::Get().ExcludeRemovedWindowEvents();
}

UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UwcClearMessages()
{
if (MessageManager::IsNull()) return;
Expand Down
30 changes: 29 additions & 1 deletion Plugins/uWindowCapture/uWindowCapture/Message.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <set>
#include "Message.h"


Expand Down Expand Up @@ -31,4 +32,31 @@ void MessageManager::ClearAll()
{
std::lock_guard<std::mutex> lock(mutex_);
messages_.clear();
}
}


void MessageManager::ExcludeRemovedWindowEvents()
{
std::lock_guard<std::mutex> lock(mutex_);

std::set<int> removedWinedowIds;
for (const auto& message : messages_)
{
if (message.type == MessageType::WindowRemoved)
{
removedWinedowIds.insert(message.windowId);
}
}

for (auto it = messages_.begin(); it != messages_.end();)
{
const auto& message = *it;
if (removedWinedowIds.find(message.windowId) != removedWinedowIds.end() &&
message.type != MessageType::WindowRemoved)
{
it = messages_.erase(it);
continue;
}
++it;
}
}
1 change: 1 addition & 0 deletions Plugins/uWindowCapture/uWindowCapture/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MessageManager
public:
void Add(Message message);
void ClearAll();
void ExcludeRemovedWindowEvents();
UINT GetCount() const;
const Message* GetHeadPointer() const;

Expand Down

0 comments on commit 360fd96

Please sign in to comment.