wind: Return more errors to the client when creating windows
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-10-13 22:33:36 +02:00
parent 3ca31770e7
commit 9097400c32
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -12,8 +12,6 @@
auto _expr_rc = (expr); \
if (!_expr_rc.has_value()) \
{ \
g_windows.remove(window); \
delete window; \
os::IPC::send_error(client.conn, _expr_rc.error()); \
return {}; \
} \
@ -65,9 +63,9 @@ static Result<void> handle_create_window_message(Client& client)
request.rect = request.rect.normalized();
auto name = TRY(String::from_cstring("Window"));
auto name = TRY_OR_IPC_ERROR(String::from_cstring("Window"));
auto shm_path = TRY(String::format("/wind-shm-%d-%lu"_sv, client.conn.fd(), time(NULL)));
auto shm_path = TRY_OR_IPC_ERROR(String::format("/wind-shm-%d-%lu"_sv, client.conn.fd(), time(NULL)));
auto* window = new (std::nothrow) Window(request.rect, move(name), request.type);
if (!window)
@ -76,12 +74,20 @@ static Result<void> handle_create_window_message(Client& client)
return {};
}
auto guard = make_scope_guard([window] {
g_windows.remove(window);
delete window;
});
window->pixels = (u32*)TRY_OR_IPC_ERROR(
os::SharedMemory::create(shm_path.view(), window->contents.height * window->contents.width * 4));
TRY_OR_IPC_ERROR(client.windows.try_append(window));
int id = static_cast<int>(client.windows.size() - 1);
// No more fallible operations, this operation is guaranteed to succeed now.
guard.deactivate();
window->client = &client;
window->id = id;