wind: Return more errors to the client when creating windows
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3ca31770e7
commit
9097400c32
14
wind/IPC.cpp
14
wind/IPC.cpp
@ -12,8 +12,6 @@
|
|||||||
auto _expr_rc = (expr); \
|
auto _expr_rc = (expr); \
|
||||||
if (!_expr_rc.has_value()) \
|
if (!_expr_rc.has_value()) \
|
||||||
{ \
|
{ \
|
||||||
g_windows.remove(window); \
|
|
||||||
delete window; \
|
|
||||||
os::IPC::send_error(client.conn, _expr_rc.error()); \
|
os::IPC::send_error(client.conn, _expr_rc.error()); \
|
||||||
return {}; \
|
return {}; \
|
||||||
} \
|
} \
|
||||||
@ -65,9 +63,9 @@ static Result<void> handle_create_window_message(Client& client)
|
|||||||
|
|
||||||
request.rect = request.rect.normalized();
|
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);
|
auto* window = new (std::nothrow) Window(request.rect, move(name), request.type);
|
||||||
if (!window)
|
if (!window)
|
||||||
@ -76,12 +74,20 @@ static Result<void> handle_create_window_message(Client& client)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto guard = make_scope_guard([window] {
|
||||||
|
g_windows.remove(window);
|
||||||
|
delete window;
|
||||||
|
});
|
||||||
|
|
||||||
window->pixels = (u32*)TRY_OR_IPC_ERROR(
|
window->pixels = (u32*)TRY_OR_IPC_ERROR(
|
||||||
os::SharedMemory::create(shm_path.view(), window->contents.height * window->contents.width * 4));
|
os::SharedMemory::create(shm_path.view(), window->contents.height * window->contents.width * 4));
|
||||||
|
|
||||||
TRY_OR_IPC_ERROR(client.windows.try_append(window));
|
TRY_OR_IPC_ERROR(client.windows.try_append(window));
|
||||||
int id = static_cast<int>(client.windows.size() - 1);
|
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->client = &client;
|
||||||
window->id = id;
|
window->id = id;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user