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

panic with NoRoomForWholeQueue #1325

Open
lestofante opened this issue Jan 5, 2020 · 3 comments
Open

panic with NoRoomForWholeQueue #1325

lestofante opened this issue Jan 5, 2020 · 3 comments
Labels

Comments

@lestofante
Copy link

lestofante commented Jan 5, 2020

my application every loop sleep 10ms (fixed refresh rate), add some data to a string (limited to 500 valid ascii) and put them into a Text widget.

Quite often I get the error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NoRoomForWholeQueue', src/libcore/result.rs:1084:5
stack backtrace:
   0:     0x560bf8d499cb - backtrace::backtrace::libunwind::trace::h89fcc71e59e3bc5b
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/libunwind.rs:88
   1:     0x560bf8d499cb - backtrace::backtrace::trace_unsynchronized::h0bad9be1379e729a
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/mod.rs:66
   2:     0x560bf8d499cb - std::sys_common::backtrace::_print::hd3382a1f33c473da
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x560bf8d499cb - std::sys_common::backtrace::print::h0ec6f03cfb8e76a6
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x560bf8d499cb - std::panicking::default_hook::{{closure}}::h96cbf7b454e3f557
                               at src/libstd/panicking.rs:200
   5:     0x560bf8d496a6 - std::panicking::default_hook::h95a8f00337383d83
                               at src/libstd/panicking.rs:214
   6:     0x560bf8d4a13d - std::panicking::rust_panic_with_hook::h92f98b46e22f14ed
                               at src/libstd/panicking.rs:477
   7:     0x560bf8d49cc2 - std::panicking::continue_panic_fmt::h25abfbb4e5b7043a
                               at src/libstd/panicking.rs:384
   8:     0x560bf8d49ba6 - rust_begin_unwind
                               at src/libstd/panicking.rs:311
   9:     0x560bf8d6530d - core::panicking::panic_fmt::h7e9f94035af782b3
                               at src/libcore/panicking.rs:85
  10:     0x560bf8d65407 - core::result::unwrap_failed::hf7591c1dd9412006
                               at src/libcore/result.rs:1084
  11:     0x560bf86bd97e - core::result::Result<T,E>::unwrap::hd1e53e065ce7d550
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libcore/result.rs:852
  12:     0x560bf86a845b - conrod_glium::Renderer::fill::he1c55c11b096ccb8
                               at /home/mauro/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod_glium-0.68.0/./src/lib.rs:661
  13:     0x560bf86aeccf - cargo_term::main::h4704b93cd0c2b45d
                               at src/main.rs:187
  14:     0x560bf866e750 - std::rt::lang_start::{{closure}}::h7f3609663d0777e4
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libstd/rt.rs:64
  15:     0x560bf8d49b43 - std::rt::lang_start_internal::{{closure}}::h4e93c1949c7a1955
                               at src/libstd/rt.rs:49
  16:     0x560bf8d49b43 - std::panicking::try::do_call::h9440ccd4dc467eaa
                               at src/libstd/panicking.rs:296
  17:     0x560bf8d4d88a - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:80
  18:     0x560bf8d4a70d - std::panicking::try::hc046e7ee42ee744f
                               at src/libstd/panicking.rs:275
  19:     0x560bf8d4a70d - std::panic::catch_unwind::h27dfc457c200aee0
                               at src/libstd/panic.rs:394
  20:     0x560bf8d4a70d - std::rt::lang_start_internal::hea1b49a567afe309
                               at src/libstd/rt.rs:48
  21:     0x560bf866e729 - std::rt::lang_start::h84e61967cd219275
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libstd/rt.rs:64
  22:     0x560bf86af6aa - main
  23:     0x7fc3c8332153 - __libc_start_main
  24:     0x560bf862d1ae - _start
  25:                0x0 - <unknown>
@lestofante
Copy link
Author

alsmost full code (it is missing support/mod.rs but is copied from the glium example:

#[macro_use] extern crate conrod_core;
extern crate conrod_glium;
#[macro_use] extern crate conrod_winit;
extern crate find_folder;
extern crate glium;
extern crate serialport;

use std::io::{self, Write};
use std::time::Duration;

use serialport::prelude::*;

mod support;

use conrod_core::{widget, Colorable, Positionable, Widget, Sizeable};
use glium::Surface;

const WIDTH: u32 = 400;
const HEIGHT: u32 = 200;

fn main() {
	// Build the window.
	let mut events_loop = glium::glutin::EventsLoop::new();
	let window = glium::glutin::WindowBuilder::new()
		.with_title("Hello Conrod!")
		.with_dimensions((WIDTH, HEIGHT).into());
	let context = glium::glutin::ContextBuilder::new()
		.with_vsync(true)
		.with_multisampling(4);
	let display = glium::Display::new(window, context, &events_loop).unwrap();
	let display = support::GliumDisplayWinitWrapper(display);

	// construct our `Ui`.
	let mut ui = conrod_core::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();

	// Generate the widget identifiers.
	widget_ids!(struct Ids { text, fps_counter });
	let ids = Ids::new(ui.widget_id_generator());

	// Add a `Font` to the `Ui`'s `font::Map` from file.
	let assets = find_folder::Search::KidsThenParents(3, 5).for_folder("assets").unwrap();
	let font_path = assets.join("fonts/NotoSans/NotoSans-Regular.ttf");
	ui.fonts.insert_from_file(font_path).unwrap();

	// A type used for converting `conrod_core::render::Primitives` into `Command`s that can be used
	// for drawing to the glium `Surface`.
	let mut renderer = conrod_glium::Renderer::new(&display.0).unwrap();

	// The image map describing each of our widget->image mappings (in our case, none).
	let image_map = conrod_core::image::Map::<glium::texture::Texture2d>::new();

	let mut events = Vec::new();

	//SERIAL STUFF

	let port_name = "/dev/ttyACM0";

	let mut settings: SerialPortSettings = Default::default();
	settings.timeout = Duration::from_millis(10);
	settings.baud_rate = 9600;

	let mut port = serialport::open_with_settings(&port_name, &settings).unwrap();
	/*
	match serialport::open_with_settings(&port_name, &settings) {
		Ok(mut port) => {
			let mut serial_buf: Vec<u8> = vec![0; 1000];
			println!("Receiving data on {} at {} baud:", &port_name, &settings.baud_rate);
			
			
		}
		Err(e) => {
			eprintln!("Failed to open \"{}\". Error: {}", port_name, e);
			::std::process::exit(1);
		}
	}
	*/


	let mut fps = 0;
	let mut fps_count_start = std::time::SystemTime::now();
	let mut t = format!("FPS: 0");
	let mut s = "ciao".to_string();
	'render: loop {
	
		std::thread::sleep(Duration::from_millis(10));
		fps += 1;
		
		let now = std::time::SystemTime::now();
		if now.duration_since(fps_count_start).unwrap() > Duration::from_millis(1000) {
		
			t = format!("FPS: {}", fps);
			
			fps = 0;
			fps_count_start = now;
			
			// Set the widgets.
			let ui = &mut ui.set_widgets();
			
		}
		
		events.clear();

		// Get all the new events since the last frame.
		events_loop.poll_events(|event| { events.push(event); });

		// If there are no new events, wait for one.
		/*
		if events.is_empty() {
			events_loop.run_forever(|event| {
				events.push(event);
				glium::glutin::ControlFlow::Break
			});
		}*/
		
		let mut serial_buf: Vec<u8> = vec![0; 1000];
		let mut serial_buf_used = 0;
		match port.read(serial_buf.as_mut_slice()) {
			Ok(t) => {/*io::stdout().write_all(&serial_buf[..t]).unwrap(); */serial_buf_used = t;},
			Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
			Err(e) => eprintln!("{:?}", e),
		}

		let len_s = s.len();
		if len_s > 500{
			s = s[len_s - 500..].to_string();
		}
		
		for byte_index in 1..serial_buf_used {
			let c = char::from(serial_buf[byte_index]);
			s.push(c);
		}
		
		println!("len is {}, readed {}", s.len(), serial_buf_used);
		
		// Process the events.
		for event in events.drain(..) {

			// Break from the loop upon `Escape` or closed window.
			match event.clone() {
				glium::glutin::Event::WindowEvent { event, .. } => {
					match event {
						glium::glutin::WindowEvent::CloseRequested |
						glium::glutin::WindowEvent::KeyboardInput {
							input: glium::glutin::KeyboardInput {
								virtual_keycode: Some(glium::glutin::VirtualKeyCode::Escape),
								..
							},
							..
						} => break 'render,
						_ => (),
					}
				}
				_ => (),
			};

			// Use the `winit` backend feature to convert the winit event to a conrod input.
			let input = match support::convert_event(event, &display) {
				None => continue,
				Some(input) => input,
			};

			// Handle the input with the `Ui`.
			ui.handle_event(input);
			
		}
		
		// Set the widgets.
		let ui = &mut ui.set_widgets();
		
		widget::Text::new(&s)
			.mid_left_of(ui.window)
			.color(conrod_core::color::WHITE)
			.font_size(30)
			//.no_line_wrap()
			.set(ids.text, ui);
			
		widget::Text::new(&t)
			.top_left_of(ui.window)
			.color(conrod_core::color::WHITE)
			.font_size(32)
			.set(ids.fps_counter, ui);

		
			
		// Draw the `Ui` if it has changed.
		if let Some(primitives) = ui.draw_if_changed() {
			renderer.fill(&display.0, primitives, &image_map);
			let mut target = display.0.draw();
			target.clear_color(0.0, 0.0, 0.0, 1.0);
			renderer.draw(&display.0, &mut target, &image_map).unwrap();
			target.finish().unwrap();
		}
	}
}

@alberdingk-thijm
Copy link
Contributor

Your string probably has too many glyphs for the cache to render it: if you check the docs, you'll notice that NoRoomForWholeQueue is an error when writing to the cache.

@alvinhochun
Copy link
Collaborator

Your window has an initial size of 400x200. The glyph cache used by the conrod_glium backend uses a texture size equal to the initial framebuffer size, which is probably too small for your use.

You can replace the line

let mut renderer = conrod_glium::Renderer::new(&display.0).unwrap();

with

let mut renderer = conrod_glium::Renderer::with_glyph_cache_dimensions(&display.0, 1024, 1024).unwrap();

to use a larger glyph cache texture. This should fix your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants