fix(wayland): account for surface data map panic

This commit is contained in:
Nova
2022-11-09 11:02:48 -05:00
parent e2b00f23ee
commit 6b578fe044
4 changed files with 22 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
use super::{state::WaylandState, surface::CoreSurface};
use smithay::{
backend::renderer::utils::on_commit_buffer_handler,
delegate_compositor,
reexports::wayland_server::protocol::wl_surface::WlSurface,
wayland::compositor::{self, CompositorHandler, CompositorState},
@@ -11,6 +12,7 @@ impl CompositorHandler for WaylandState {
}
fn commit(&mut self, surface: &WlSurface) {
on_commit_buffer_handler(surface);
compositor::with_states(surface, |data| {
data.data_map.insert_if_missing_threadsafe(|| {
CoreSurface::new(

View File

@@ -146,9 +146,15 @@ impl Wayland {
let time_ms = (sk.time_getf() * 1000.) as u64;
for core_surface in CORE_SURFACES.get_valid_contents() {
let client_id = core_surface.wl_surface().client().unwrap().id();
let client_id = match core_surface.wl_surface().client() {
Some(client) => client.id(),
None => continue,
};
let state = self.state.lock();
let seat_data = state.seats.get(&client_id).unwrap().clone();
let seat_data = match state.seats.get(&client_id) {
Some(seat_data) => seat_data.clone(),
None => continue,
};
let output = state.output.clone();
core_surface.process(
sk,

View File

@@ -44,6 +44,7 @@ impl ClientData for ClientState {
pub struct WaylandState {
pub weak_ref: Weak<Mutex<WaylandState>>,
pub log: Logger,
pub display: Arc<Mutex<Display<WaylandState>>>,
pub display_handle: DisplayHandle,
@@ -102,6 +103,7 @@ impl WaylandState {
Arc::new_cyclic(|weak| {
Mutex::new(WaylandState {
weak_ref: weak.clone(),
log,
display,
display_handle,

View File

@@ -10,7 +10,7 @@ use slog::Logger;
use smithay::{
backend::renderer::{
gles2::{Gles2Renderer, Gles2Texture},
utils::{import_surface_tree, on_commit_buffer_handler, RendererSurfaceStateUserData},
utils::{import_surface_tree, RendererSurfaceStateUserData},
Texture,
},
desktop::utils::send_frames_surface_tree,
@@ -18,7 +18,7 @@ use smithay::{
reexports::wayland_server::{
backend::ObjectId, protocol::wl_surface::WlSurface, Display, DisplayHandle, Resource,
},
wayland::compositor::{self, SurfaceData},
wayland::compositor::{self, SurfaceData, SurfaceUserData},
};
use std::{
sync::{Arc, Weak},
@@ -128,10 +128,15 @@ impl CoreSurface {
on_mapped: F,
if_mapped: M,
) {
// Let Smithay handle all the buffer maintenance
on_commit_buffer_handler(&self.wl_surface());
// Avoid a panic in rare cases
if self.wl_surface().data::<SurfaceUserData>().is_none() {
return;
}
// Import all surface buffers into textures
import_surface_tree(renderer, &self.wl_surface(), log).unwrap();
if import_surface_tree(renderer, &self.wl_surface(), log).is_err() {
return;
}
let mapped = compositor::with_states(&self.wl_surface(), |data| {
data.data_map