Skip to content

Commit

Permalink
#2522 fix issue that could cause a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jan 22, 2025
1 parent dafb6d6 commit eb10f87
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Config *global setting* `split_type` is now categorized as a *space setting* instead [#2479](https://github.com/koekeishiya/yabai/issues/2479)
- Additional options `x-axis` and `y-axis` can now be used with `config auto_balance` command [#190](https://github.com/koekeishiya/yabai/issues/190)
- Minor adjustment to screen-padding and window-gap [#2502](https://github.com/koekeishiya/yabai/issues/2502)
- Fix issue that could cause a crash when a newly launched application terminates rapidly during/after launch [#2522](https://github.com/koekeishiya/yabai/issues/2522)

## [7.1.5] - 2024-11-01
### Changed
Expand Down
1 change: 1 addition & 0 deletions src/process_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static PROCESS_EVENT_HANDLER(process_handler)

__atomic_store_n(&process->terminated, true, __ATOMIC_RELEASE);
process_manager_remove_process(pm, &psn);
workspace_application_unobserve(g_workspace_context, process);
__asm__ __volatile__ ("" ::: "memory");

event_loop_post(&g_event_loop, APPLICATION_TERMINATED, process, 0);
Expand Down
1 change: 1 addition & 0 deletions src/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static inline bool workspace_is_macos_##name(void) \
struct process;
void *workspace_application_create_running_ns_application(struct process *process);
void workspace_application_destroy_running_ns_application(void *context, struct process *process);
void workspace_application_unobserve(void *context, struct process *process);
bool workspace_application_is_observable(struct process *process);
bool workspace_application_is_finished_launching(struct process *process);
void workspace_application_observe_finished_launching(void *context, struct process *process);
Expand Down
18 changes: 16 additions & 2 deletions src/workspace.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ void workspace_application_observe_activation_policy(void *context, struct proce
}
}

void workspace_application_unobserve(void *ws_context, struct process *process)
{
NSRunningApplication *application = __atomic_load_n(&process->ns_application, __ATOMIC_RELAXED);
if (application) {
@try {
[application removeObserver:ws_context forKeyPath:@"activationPolicy" context:process];
} @catch (NSException * __unused exception) {}

@try {
[application removeObserver:ws_context forKeyPath:@"finishedLaunching" context:process];
} @catch (NSException * __unused exception) {}
}
}

bool workspace_application_is_observable(struct process *process)
{
NSRunningApplication *application = __atomic_load_n(&process->ns_application, __ATOMIC_RELAXED);
Expand Down Expand Up @@ -196,7 +210,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
{
if ([keyPath isEqualToString:@"activationPolicy"]) {
struct process *process = context;
assert(!process->terminated);
if (process->terminated) return;

id result = [change objectForKey:NSKeyValueChangeNewKey];
if ([result intValue] != process->policy) {
Expand All @@ -221,7 +235,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N

if ([keyPath isEqualToString:@"finishedLaunching"]) {
struct process *process = context;
assert(!process->terminated);
if (process->terminated) return;

id result = [change objectForKey:NSKeyValueChangeNewKey];
if ([result intValue] == 1) {
Expand Down

0 comments on commit eb10f87

Please sign in to comment.