Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on Windows when loading model version #1304

Merged
merged 5 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions crates/fj-host/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,27 @@ impl Model {
let version_pkg: libloading::Symbol<fn() -> RawVersion> =
lib.get(b"version_pkg").map_err(Error::LoadingVersion)?;

let version_pkg = version_pkg();
if fj::version::VERSION_PKG != version_pkg.as_str() {
let version_pkg = version_pkg().to_string();
if fj::version::VERSION_PKG != version_pkg {
let host = String::from_utf8_lossy(
fj::version::VERSION_PKG.as_bytes(),
)
.into_owned();
let model =
String::from_utf8_lossy(version_pkg.as_str().as_bytes())
.into_owned();
let model = version_pkg;

return Err(Error::VersionMismatch { host, model });
}

let version_full: libloading::Symbol<fn() -> RawVersion> =
lib.get(b"version_full").map_err(Error::LoadingVersion)?;

let version_full = version_full();
if fj::version::VERSION_FULL != version_full.as_str() {
let version_full = version_full().to_string();
if fj::version::VERSION_FULL != version_full {
let host = String::from_utf8_lossy(
fj::version::VERSION_FULL.as_bytes(),
)
.into_owned();
let model =
String::from_utf8_lossy(version_full.as_str().as_bytes())
.into_owned();
let model = version_full;

warn!("{}", Error::VersionMismatch { host, model });
}
Expand Down
14 changes: 1 addition & 13 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,7 @@ pub fn run(
}

ModelEvent::Error(err) => {
// Can be cleaned up, once `Report` is stable:
// https://doc.rust-lang.org/std/error/struct.Report.html

println!("Error receiving updated shape: {}", err);

let mut current_err = &err as &dyn error::Error;
while let Some(err) = current_err.source() {
println!();
println!("Caused by:");
println!(" {}", err);

current_err = err;
}
status.update_status(&err.to_string());
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/fj/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ impl RawVersion {
///
/// Must be a `RawVersion` returned from one of the hidden version functions
/// in this module.
pub unsafe fn as_str(&self) -> &str {
#[allow(clippy::inherent_to_string)]
pub unsafe fn to_string(&self) -> String {
let slice = slice::from_raw_parts(self.ptr, self.len);
std::str::from_utf8(slice).unwrap()
String::from_utf8_lossy(slice).into_owned()
}
}

Expand Down