Skip to content

Commit 7867950

Browse files
committed
Fix window ID map key type for macOS
Changed the key type in the window_id_map from NSWindow* to void* to avoid hash function issues with Objective-C pointers. This ensures consistent and reliable mapping of window IDs.
1 parent 429fa1a commit 7867950

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/platform/macos/window_macos.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,21 @@
368368
}
369369

370370
// Store the allocated ID in a static map to ensure consistency
371-
static std::unordered_map<NSWindow*, WindowId> window_id_map;
371+
// Use void* as key to avoid hash function issues with Objective-C pointers
372+
static std::unordered_map<void*, WindowId> window_id_map;
372373
static std::mutex map_mutex;
373374

375+
void* window_ptr = (__bridge void*)pimpl_->ns_window_;
374376
std::lock_guard<std::mutex> lock(map_mutex);
375-
auto it = window_id_map.find(pimpl_->ns_window_);
377+
auto it = window_id_map.find(window_ptr);
376378
if (it != window_id_map.end()) {
377379
return it->second;
378380
}
379381

380382
// Allocate new ID using the IdAllocator
381383
WindowId new_id = IdAllocator::Allocate<Window>();
382384
if (new_id != IdAllocator::kInvalidId) {
383-
window_id_map[pimpl_->ns_window_] = new_id;
385+
window_id_map[window_ptr] = new_id;
384386

385387
// Register window in registry (delayed registration)
386388
// This requires the Window to be managed by shared_ptr

0 commit comments

Comments
 (0)