diff options
author | Arisotura <thetotalworm@gmail.com> | 2023-12-23 23:59:59 +0100 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2023-12-23 23:59:59 +0100 |
commit | de4ae9dd92761b552f23401a3b1336a0b4ab8641 (patch) | |
tree | b68eed9c4bc8d0d03ccf417fe7a89206c11be11a | |
parent | 989b93c92ab03985426619f6fc4d0076fa973406 (diff) |
fix possible crash
-rw-r--r-- | src/frontend/qt_sdl/LocalMP.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index 466f90c..7ea9868 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -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; } @@ -328,6 +330,7 @@ void SetRecvTimeout(int timeout) void Begin() { + if (!MPQueue) return; MPQueue->lock(); MPQueueHeader* header = (MPQueueHeader*)MPQueue->data(); PacketReadOffset = header->PacketWriteOffset; @@ -340,6 +343,7 @@ void Begin() void End() { + if (!MPQueue) return; MPQueue->lock(); MPQueueHeader* header = (MPQueueHeader*)MPQueue->data(); //SemReset(InstanceID); @@ -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]; @@ -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)) @@ -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 @@ -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; |