Skip to content

Commit

Permalink
fix possible crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Dec 23, 2023
1 parent 989b93c commit de4ae9d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/frontend/qt_sdl/LocalMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ bool Init()
Log(LogLevel::Info, "MP sharedmem doesn't exist. creating\n");
if (!MPQueue->create(kQueueSize))
{
Log(LogLevel::Error, "MP sharedmem create failed :(\n");
Log(LogLevel::Error, "MP sharedmem create failed :( (%d)\n", MPQueue->error());
delete MPQueue;
MPQueue = nullptr;
return false;
}

Expand Down Expand Up @@ -328,6 +330,7 @@ void SetRecvTimeout(int timeout)

void Begin()
{
if (!MPQueue) return;
MPQueue->lock();
MPQueueHeader* header = (MPQueueHeader*)MPQueue->data();
PacketReadOffset = header->PacketWriteOffset;
Expand All @@ -340,6 +343,7 @@ void Begin()

void End()
{
if (!MPQueue) return;
MPQueue->lock();
MPQueueHeader* header = (MPQueueHeader*)MPQueue->data();
//SemReset(InstanceID);
Expand Down Expand Up @@ -421,6 +425,7 @@ void FIFOWrite(int fifo, void* buf, int len)

int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp)
{
if (!MPQueue) return 0;
MPQueue->lock();
u8* data = (u8*)MPQueue->data();
MPQueueHeader* header = (MPQueueHeader*)&data[0];
Expand Down Expand Up @@ -476,6 +481,7 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp)

int RecvPacketGeneric(u8* packet, bool block, u64* timestamp)
{
if (!MPQueue) return 0;
for (;;)
{
if (!SemWait(InstanceID, block ? RecvTimeout : 0))
Expand Down Expand Up @@ -552,6 +558,8 @@ int SendAck(u8* packet, int len, u64 timestamp)

int RecvHostPacket(u8* packet, u64* timestamp)
{
if (!MPQueue) return -1;

if (LastHostID != -1)
{
// check if the host is still connected
Expand All @@ -571,6 +579,8 @@ int RecvHostPacket(u8* packet, u64* timestamp)

u16 RecvReplies(u8* packets, u64 timestamp, u16 aidmask)
{
if (!MPQueue) return 0;

u16 ret = 0;
u16 myinstmask = (1 << InstanceID);
u16 curinstmask;
Expand Down

0 comments on commit de4ae9d

Please sign in to comment.