Skip to content

Commit

Permalink
port: Fix export_to_path producing a !Send future.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Dec 11, 2023
1 parent 3fdaad1 commit 627ea86
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
57 changes: 30 additions & 27 deletions all-is-cubes-port/src/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,37 +395,40 @@ pub(crate) async fn export_gltf(
let mesh_options = MeshOptions::new(&GraphicsOptions::default());

for (mut p, block_def_ref) in progress.split_evenly(block_defs.len()).zip(block_defs) {
let block_def = block_def_ref.read()?;
let name = block_def_ref.name();
p.set_label(&name);
p.progress(0.01).await;
let mesh = SpaceMesh::<GltfMt>::from(&BlockMesh::new(
&block_def
.evaluate()
.map_err(|eve| ExportError::NotRepresentable {
name: Some(name.clone()),
reason: format!("block evaluation failed: {eve}"),
})?,
&writer.texture_allocator(),
&mesh_options,
));

let mesh_index = writer.add_mesh(&name, &mesh);
// TODO: if the mesh is empty/None, should we include the node anyway or not?
let mesh_node = push_and_return_index(
&mut writer.root.nodes,
gltf_json::Node {
mesh: mesh_index,
..empty_node(Some(name.to_string()))
},
);
{
// constrained scope so we don't hold UBorrow over an await
let block_def = block_def_ref.read()?;
let mesh = SpaceMesh::<GltfMt>::from(&BlockMesh::new(
&block_def
.evaluate()
.map_err(|eve| ExportError::NotRepresentable {
name: Some(name.clone()),
reason: format!("block evaluation failed: {eve}"),
})?,
&writer.texture_allocator(),
&mesh_options,
));

let mesh_index = writer.add_mesh(&name, &mesh);
// TODO: if the mesh is empty/None, should we include the node anyway or not?
let mesh_node = push_and_return_index(
&mut writer.root.nodes,
gltf_json::Node {
mesh: mesh_index,
..empty_node(Some(name.to_string()))
},
);

writer.root.scenes.push(json::Scene {
name: Some(format!("{name} display scene")),
nodes: vec![mesh_node],
extensions: None,
extras: Default::default(),
});
writer.root.scenes.push(json::Scene {
name: Some(format!("{name} display scene")),
nodes: vec![mesh_node],
extensions: None,
extras: Default::default(),
});
}

p.finish().await;
}
Expand Down
17 changes: 17 additions & 0 deletions all-is-cubes-port/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ fn errors_are_send_sync() {
assert_send_sync::<ExportError>();
}

/// This function won't compile if `load_universe_from_file`'s future isn't Send
fn _load_universe_from_file_future_is_send() {
#![allow(unreachable_code, clippy::diverging_sub_expression)]
tokio::spawn(load_universe_from_file(unreachable!(), unreachable!()));
}

#[tokio::test]
async fn import_unknown_format() {
let error = load_universe_from_file(
Expand All @@ -38,6 +44,17 @@ async fn import_unknown_format() {
);
}

/// This function won't compile if `export_to_path`'s future isn't Send
fn _export_to_path_future_is_send() {
#![allow(unreachable_code, clippy::diverging_sub_expression)]
tokio::spawn(export_to_path(
unreachable!(),
unreachable!(),
unreachable!(),
unreachable!(),
));
}

#[test]
fn member_export_path() {
let mut universe = Universe::new();
Expand Down

0 comments on commit 627ea86

Please sign in to comment.