From c0e2b5d53f3980c0ebc6cd8bea26d8445ea4ab18 Mon Sep 17 00:00:00 2001 From: Markus Ast Date: Sat, 21 Aug 2021 18:25:50 +0200 Subject: [PATCH] work around a crash when returning an error to Lua Refs #19 --- src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ee2b6929..0cbc4412 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,9 +174,16 @@ fn next(lua: &Lua, callback: Function) -> LuaResult { } fn event(lua: &Lua, event: Value) -> LuaResult<()> { - let event: Event = lua - .from_value(event) - .map_err(|err| mlua::Error::ExternalError(Arc::new(Error::DeserializeParams(err))))?; + let event: Event = match lua.from_value(event) { + Ok(event) => event, + Err(err) => { + log::error!("failed to deserialize event: {}", err); + // In certain cases DCS crashes when we receive an error here (see + // https://github.com/DCS-gRPC/rust-server/issues/19), which we are working around + // by intercepting and logging the error instead. + return Ok(()); + } + }; if let Some(Server { ref ipc,