Skip to content

Commit

Permalink
Merge pull request #152 from ai-zen/master
Browse files Browse the repository at this point in the history
Fix fatal error of `SteamAPIInitError::from_result_and_message`.
  • Loading branch information
Noxime authored Jan 22, 2024
2 parents bedbdc5 + 806f84a commit a204e81
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::sys;
use std::{
convert::TryFrom,
ffi::{c_char, CString},
ffi::{c_char, CStr},
};

/// Covers errors that can be returned by the steamworks API
Expand Down Expand Up @@ -755,8 +755,10 @@ impl SteamAPIInitError {
result: sys::ESteamAPIInitResult,
message: sys::SteamErrMsg,
) -> Self {
let err_str = unsafe { CString::from_raw(message.as_ptr() as *mut c_char) };
let err_string = err_str.into_string().unwrap();
let err_string = unsafe {
let cstr = CStr::from_ptr(message.as_ptr() as *const c_char);
cstr.to_string_lossy().to_owned().into_owned()
};

match result {
sys::ESteamAPIInitResult::k_ESteamAPIInitResult_FailedGeneric => {
Expand Down

0 comments on commit a204e81

Please sign in to comment.