From 8f1d03cd75824dc149bda275643c502fcd1448e8 Mon Sep 17 00:00:00 2001 From: Jonas Holzman Date: Tue, 25 Feb 2025 16:24:55 +0100 Subject: [PATCH] Fix #133713: Crash when drag and dropping bitmap images on macOS Drag and dropping bitmap images (as in drag and dropping directly from another software such as a web browser, not from an image file in Finder) inside the Blender window on macOS would segfault due to the dropped image being [autorelease]d even though its data was meant to outlive the function scope. Fixed by removing the superflous autorelease and adding a comment note. The only caller of this function (GHOST_SystemCocoa::handleDraggingEvent) already properly [release]s the image in question. Note that currently, non-file/bitmap image drag and drop is not implemented on the WM side, and as such this feature/GHOST event does not do anything practical. Pull Request: https://projects.blender.org/blender/blender/pulls/135076 --- intern/ghost/intern/GHOST_WindowCocoa.mm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index 2550ab68ca1..64298bf85d0 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -270,14 +270,12 @@ switch (m_draggedObjectType) { case GHOST_kDragnDropTypeBitmap: { - if ([NSImage canInitWithPasteboard:draggingPBoard]) { - NSImage *droppedImg = [[[NSImage alloc] initWithPasteboard:draggingPBoard] autorelease]; - data = droppedImg; // [draggingPBoard dataForType:NSPasteboardTypeTIFF]; - } - else { + if (![NSImage canInitWithPasteboard:draggingPBoard]) { return NO; } - + /* Caller must [release] the returned data in this case. */ + NSImage *droppedImg = [[NSImage alloc] initWithPasteboard:draggingPBoard]; + data = droppedImg; break; } case GHOST_kDragnDropTypeFilenames: