iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
24.57k stars 1.14k forks source link

White Screen. #1338

Open ghost opened 2 years ago

ghost commented 2 years ago

Is there an existing issue for this?

Is this issue related to iced?

What happened?

I have wrote the following file

use iced::{
    canvas::{Cache, Cursor, Geometry, Path},
    executor, time,
    widget::canvas::{
        event::{self, Event},
        Program,
    },
    Application, Color, Command, Element, Point, Rectangle, Settings, Subscription, Canvas,
};

struct Example;

#[derive(Debug)]
enum Message {}

#[derive(Debug)]
struct ProgramCanvas {
    cache: Cache,
}

impl Application for Example {
    type Executor = executor::Default;
    type Message = Message;
    type Flags = bool;

    fn new(_flags: Self::Flags) -> (Example, Command<Self::Message>) {
        (Example, Command::none())
    }

    fn title(&self) -> String {
        String::from("Title")
    }

    fn update(&mut self ,_: Self::Message) -> Command<Self::Message> {
        Command::none()
    }

    fn view(&mut self) -> Element<Self::Message> {
        use iced::{Container, Length};
        Canvas::new(ProgramCanvas::new())
        .width(Length::Fill)
        .height(Length::Fill)
        .into()
    }
}

impl ProgramCanvas {
    fn new() -> Self {
        Self {
            cache: Cache::new(),
        }
    }
}

impl Program<Message> for ProgramCanvas {
    fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry> {
        let chip_view = self.cache.draw(bounds.size(), |frame| {
            let space = Path::rectangle(Point::ORIGIN, frame.size());
            frame.fill(&space, Color::BLACK);
            log::info!("DRAWING");
            frame.translate(frame.center() - Point::ORIGIN);
        });
        vec![chip_view]
    }
}

pub fn main() -> iced::Result {
    Example::run(Settings {
        id: Some(String::from("Some")),
        window: iced::window::Settings {
            size: (64 * 15, 32 * 15),
            min_size: Some((64 * 15, 32 * 15)),
            max_size: Some((64 * 15, 32 * 15)),
            resizable: false,
            ..iced::window::Settings::default()
        },
        flags: false,
        default_font: None,
        default_text_size: 20,
        text_multithreading: false,
        antialiasing: true,
        exit_on_close_request: true,
        try_opengles_first: false,
    })
}

with the following Cargo.toml

[package]
name = "example"
version = "0.1.0"
edition = "2021"

[dependencies]
rand = "0.8.4"
iced = { version = "~0.4" , features = ["canvas", "tokio"] }
iced_native = "~0.4"
rodio = "0.15.0"
log = "0.4.16"
env_logger = "0.9.0"
builder-pattern = "0.4.2"
byteorder = "1.4.3"

And I am only getting a white screen.

What is the expected behavior?

A black screen

Version

master

Operative System

Linux

Do you have any log output?

No response

hecrj commented 2 years ago
ghost commented 2 years ago

@hecrj

The example clock is a white screen. The example game_of_life is no working properly, does no show any cell. The example solar system is a white screen.

The Cargo.toml can be reduced to

[package]
name = "example"
version = "0.1.0"
edition = "2021"

[dependencies]
iced = { version = "~0.4" , features = ["canvas", "tokio"] }
iced_native = "~0.4"
log = "0.4.16"
env_logger = "0.9.0"

The disabling of anti-aliasing does in fact solve the problem. The enabling to the feature glow does in fact also solve the problem. And the mixing of two also solve the problem.

xTekC commented 2 years ago

@hecrj On Arch Linux I have solved this problem before when using iced. Adding the "glow" feature to each iced project while using Arch Linux and likely other Linux distros solves the problem and everything works properly.

Close issue

scottrick commented 2 years ago

I was seeing the same issue (although solar_system was black instead of white). Adding feature "glow" fixed it for me. Running Ubuntu 22.04.

silven commented 2 years ago

I checked out iced for the first time today. I also had the issue that every Canvas was just white. Activating "glow" feature makes it work. Also running ubuntu 22.04.

MichalLebeda commented 2 years ago

@hecrj Close issue

No, It does not fix the problem, it just switches to OpenGL.

Having same problem on Arch. Glow works as others mentioned

greatest-ape commented 1 year ago

I’m having reports of what is likely the same issue: https://github.com/greatest-ape/OctaSine/issues/136#issuecomment-1428668787

jw3 commented 1 year ago

At 0.10 without glow, is there a solution other than disabling antialiasing?