Fix segfault on exit when dmabuf capturing is selected

vencrypt
Andri Yngvason 2020-01-04 13:48:09 +00:00
parent 457e540d89
commit c5fee473d6
2 changed files with 30 additions and 13 deletions

View File

@ -217,7 +217,8 @@ void wayvnc_destroy(struct wayvnc* self)
zwlr_virtual_pointer_manager_v1_destroy(self->pointer_backend.manager); zwlr_virtual_pointer_manager_v1_destroy(self->pointer_backend.manager);
pointer_destroy(&self->pointer_backend); pointer_destroy(&self->pointer_backend);
zwlr_screencopy_manager_v1_destroy(self->screencopy_backend.manager); if (self->screencopy_backend.manager)
zwlr_screencopy_manager_v1_destroy(self->screencopy_backend.manager);
if (self->dmabuf_backend.manager) if (self->dmabuf_backend.manager)
zwlr_export_dmabuf_manager_v1_destroy(self->dmabuf_backend.manager); zwlr_export_dmabuf_manager_v1_destroy(self->dmabuf_backend.manager);
@ -248,10 +249,9 @@ static int init_wayland(struct wayvnc* self)
wl_display_roundtrip(self->display); wl_display_roundtrip(self->display);
wl_display_dispatch(self->display); wl_display_dispatch(self->display);
if (!self->dmabuf_backend.manager) { if (!self->dmabuf_backend.manager && !self->screencopy_backend.manager) {
log_error("Compositor does not support %s.\n", log_error("Compositor supports neither screencopy nor export-dmabuf! Exiting.\n");
zwlr_export_dmabuf_manager_v1_interface.name); goto failure;
goto export_manager_failure;
} }
self->dmabuf_backend.fc.on_done = on_capture_done; self->dmabuf_backend.fc.on_done = on_capture_done;
@ -262,8 +262,6 @@ static int init_wayland(struct wayvnc* self)
return 0; return 0;
export_manager_failure:
output_list_destroy(&self->outputs);
failure: failure:
wl_display_disconnect(self->display); wl_display_disconnect(self->display);
return -1; return -1;
@ -522,8 +520,7 @@ int main(int argc, char* argv[])
int port = DEFAULT_PORT; int port = DEFAULT_PORT;
int output_id = -1; int output_id = -1;
enum frame_capture_backend_type fcbackend = enum frame_capture_backend_type fcbackend = FRAME_CAPTURE_BACKEND_NONE;
FRAME_CAPTURE_BACKEND_SCREENCOPY;
const char* seat_name = NULL; const char* seat_name = NULL;
static const char* shortopts = "c:o:k:s:h"; static const char* shortopts = "c:o:k:s:h";
@ -656,18 +653,36 @@ int main(int argc, char* argv[])
if (init_nvnc(&self, address, port) < 0) if (init_nvnc(&self, address, port) < 0)
goto nvnc_failure; goto nvnc_failure;
screencopy_init(&self.screencopy_backend); if (self.screencopy_backend.manager)
dmabuf_capture_init(&self.dmabuf_backend); screencopy_init(&self.screencopy_backend);
if (self.dmabuf_backend.manager)
dmabuf_capture_init(&self.dmabuf_backend);
switch (fcbackend) { switch (fcbackend) {
case FRAME_CAPTURE_BACKEND_SCREENCOPY: case FRAME_CAPTURE_BACKEND_SCREENCOPY:
if (!self.screencopy_backend.manager) {
log_error("screencopy is not supported by compositor\n");
goto capture_failure;
}
self.capture_backend = &self.screencopy_backend.frame_capture; self.capture_backend = &self.screencopy_backend.frame_capture;
break; break;
case FRAME_CAPTURE_BACKEND_DMABUF: case FRAME_CAPTURE_BACKEND_DMABUF:
if (!self.screencopy_backend.manager) {
log_error("export-dmabuf is not supported by compositor\n");
goto capture_failure;
}
self.capture_backend = &self.dmabuf_backend.fc; self.capture_backend = &self.dmabuf_backend.fc;
break; break;
case FRAME_CAPTURE_BACKEND_NONE: case FRAME_CAPTURE_BACKEND_NONE:
abort(); if (self.screencopy_backend.manager)
self.capture_backend = &self.screencopy_backend.frame_capture;
else if (self.dmabuf_backend.manager)
self.capture_backend = &self.dmabuf_backend.fc;
else
goto capture_failure;
break; break;
} }

View File

@ -252,5 +252,7 @@ void screencopy_init(struct screencopy* self)
void screencopy_destroy(struct screencopy* self) void screencopy_destroy(struct screencopy* self)
{ {
uv_timer_stop(&self->timer); uv_timer_stop(&self->timer);
wl_buffer_destroy(self->buffer);
if (self->buffer)
wl_buffer_destroy(self->buffer);
} }