hedgewars/uFLIPC.pas
branchqmlfrontend
changeset 11451 6e9b12864856
parent 11450 0c75fa9ce340
child 11452 78860824b5a5
--- a/hedgewars/uFLIPC.pas	Thu Dec 10 00:33:45 2015 +0300
+++ b/hedgewars/uFLIPC.pas	Thu Dec 10 23:49:12 2015 +0300
@@ -7,6 +7,7 @@
 
 procedure ipcToEngine(s: shortstring);
 procedure ipcToEngineRaw(p: pointer; len: Longword);
+procedure ipcCleanEngineQueue();
 //function  ipcReadFromEngine: shortstring;
 //function  ipcCheckFromEngine: boolean;
 
@@ -99,6 +100,36 @@
     ipcSend(msg, queueFrontend)
 end;
 
+procedure ipcCleanEngineQueue();
+var pmsg, t: PIPCMessage;
+    q: PIPCQueue;
+begin
+    q:= queueEngine;
+
+    SDL_LockMutex(q^.mut);
+
+    pmsg:= @q^.msg;
+    q^.last:= pmsg;
+
+    while pmsg <> nil do
+    begin
+        t:= pmsg^.next;
+
+        if pmsg^.buf <> nil then
+            FreeMem(pmsg^.buf, pmsg^.len);
+
+        if pmsg <> @q^.msg then
+            dispose(pmsg);
+        pmsg:= t
+    end;
+
+    q^.msg.next:= nil;
+    q^.msg.str[0]:= #0;
+    q^.msg.buf:= nil;
+
+    SDL_UnlockMutex(q^.mut);
+end;
+
 procedure ipcToNet(s: shortstring);
 var msg: TIPCMessage;
 begin