FyroxEngine / Fyrox

3D and 2D game engine written in Rust

Home Page:https://fyrox.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable power saving mode back in the editor on Linux

mrDIMAS opened this issue · comments

Power-saving mode is disabled on Linux for now because of a subtle bug in winit which cannot handle control flow juggling properly on Wayland causing the editor to crash. This is mostly a tracking issue.

There may be a way to create a minimal working example in pure winit in order to report this bug to winit team, but until now, I am not able to reproduce this bug in pure winit. So I put the codes here. If anyone can make a minimal example and reproduce the bug, please report to winit's github.

use winit::{
    event_loop::{EventLoop, ControlFlow},
    window::WindowBuilder,
};

fn main() {
    let event_loop = EventLoop::new().unwrap();

    let window = WindowBuilder::new()
        .build(&event_loop)
        .unwrap();

    event_loop.run(move |event, elwt| {
        elwt.set_control_flow(ControlFlow::Wait);
    })
    .unwrap();
}

I guess we (you 😅 ) should also try

use winit::{
    event::Event,
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

fn main() {
    let event_loop = EventLoop::new().unwrap();

    let window = WindowBuilder::new().build(&event_loop).unwrap();

    let mut counter = 300;
    event_loop
        .run(move |event, elwt| {
            if let Event::AboutToWait = event {
                if counter > 0 {
                    window.request_redraw();
                    counter -= 1;
                }
            }

            if counter > 0 {
                elwt.set_control_flow(ControlFlow::Poll);
            } else {
                elwt.set_control_flow(ControlFlow::Wait);
            }
        })
        .unwrap();
}

This is the closest code to what the editor does on startup.