Skip to content

Commit cb4f7f9

Browse files
committed
Fixes for macos.
1 parent 6e8941c commit cb4f7f9

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

crates/processing_pyo3/src/lib.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,7 @@ fn dispatch_event_callbacks(locals: &Bound<'_, PyAny>) -> PyResult<()> {
162162
Ok(())
163163
}
164164

165-
fn create_graphics_context(
166-
module: &Bound<'_, PyModule>,
167-
width: u32,
168-
height: u32,
169-
) -> PyResult<()> {
165+
fn create_graphics_context(module: &Bound<'_, PyModule>, width: u32, height: u32) -> PyResult<()> {
170166
let py = module.py();
171167
let env = detect_environment(py)?;
172168

@@ -185,8 +181,7 @@ fn create_graphics_context(
185181
match env.as_str() {
186182
"jupyter" => {
187183
let asset_path = get_asset_root()?;
188-
let graphics =
189-
Graphics::new_offscreen(width, height, asset_path.as_str(), log_level)?;
184+
let graphics = Graphics::new_offscreen(width, height, asset_path.as_str(), log_level)?;
190185
module.setattr("_graphics", graphics)?;
191186

192187
if !has_existing {
@@ -217,9 +212,7 @@ fn create_graphics_context(
217212

218213
let post_code = CString::new(IPYTHON_POST_EXECUTE_CODE)?;
219214
py.run(post_code.as_c_str(), None, None).map_err(|e| {
220-
PyRuntimeError::new_err(format!(
221-
"Failed to register post-execute hook: {e}"
222-
))
215+
PyRuntimeError::new_err(format!("Failed to register post-execute hook: {e}"))
223216
})?;
224217
}
225218
}
@@ -894,9 +887,15 @@ mod mewnala {
894887
frame.getattr("f_globals")?
895888
};
896889
sync_globals(module, &globals)?;
897-
898-
// if there's no draw fn, we enter an idle loop
890+
891+
// no draw is defined. flush any top level code and then idle
899892
if draw_fn.is_none() {
893+
{
894+
let mut graphics = get_graphics_mut(module)?
895+
.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
896+
graphics.surface.poll_events();
897+
}
898+
900899
get_graphics(module)?
901900
.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?
902901
.end_draw()?;
@@ -917,7 +916,6 @@ mod mewnala {
917916
}
918917
let draw_fn_ref = draw_fn.as_mut().expect("checked above");
919918

920-
// start draw loop
921919
loop {
922920
{
923921
let mut graphics = get_graphics_mut(module)?

crates/processing_render/src/graphics.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ pub fn begin_draw(In(entity): In<Entity>, mut state_query: Query<&mut RenderStat
445445
}
446446

447447
pub fn flush(app: &mut App, entity: Entity) -> Result<()> {
448+
// f there's nothing to render, skip the whole render pass. this avoids some issues on
449+
// macos with msaa resolve where nothing is rendered
450+
let is_empty = graphics_mut!(app, entity)
451+
.get::<CommandBuffer>()
452+
.map(|c| c.commands.is_empty())
453+
.unwrap_or(true);
454+
if is_empty {
455+
return Ok(());
456+
}
457+
448458
graphics_mut!(app, entity).insert(Flush);
449459
app.update();
450460
graphics_mut!(app, entity).remove::<Flush>();

0 commit comments

Comments
 (0)