From c70ac2e76a0acfa27d64a25d11ed890ec356011e Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Sun, 8 Sep 2024 20:26:21 +0200 Subject: [PATCH] Add try/catch block around message queue recive method in the engine --- src/vizdoom/src/viz_message_queue.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/vizdoom/src/viz_message_queue.cpp b/src/vizdoom/src/viz_message_queue.cpp index 8cba35f4d..bf8907e34 100644 --- a/src/vizdoom/src/viz_message_queue.cpp +++ b/src/vizdoom/src/viz_message_queue.cpp @@ -68,12 +68,19 @@ void VIZ_MQSend(uint8_t code, const char * command){ } void VIZ_MQReceive(void *msg) { - size_t size; - unsigned int priority; + if(vizMQDoom) { + size_t size; + unsigned int priority; - if(vizMQDoom) vizMQDoom->receive(msg, sizeof(VIZMessage), size, priority); + try{ + vizMQDoom->receive(msg, sizeof(VIZMessage), size, priority); + } + catch(...){ // bip::interprocess_exception + VIZ_Error(VIZ_FUNC, "Failed to receive message."); + } - VIZ_DebugMsg(4, VIZ_FUNC, "Received msg: %d.", static_cast(msg)->code); + VIZ_DebugMsg(4, VIZ_FUNC, "Received msg: %d.", static_cast(msg)->code); + } } bool VIZ_MQTryReceive(void *msg){