Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/AppKit/NSImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public static NSImage FromStream (System.IO.Stream stream)
}
}

public NSImage (string fileName, bool lazy)
{
if (lazy)
Handle = InitByReferencingFile (fileName);
else
Handle = new NSImage (fileName).Handle;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, now you have two managed objects using the same native handle.

This means the moment the GC collects one of them, the other will point to random memory, and crash when used.

My suggestion here would be to add another interna binding for this overload, and use that instead (like you did for InitByReferencingFile).

}

public NSImage (NSData data, bool ignoresOrientation)
{
if (ignoresOrientation) {
Expand Down
5 changes: 3 additions & 2 deletions src/appkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8183,15 +8183,16 @@ public partial interface NSImage : NSCoding, NSCopying, NSSecureCoding, NSPasteb
[Export ("initWithContentsOfURL:")]
IntPtr Constructor (NSUrl url);

//[Export ("initByReferencingFile:")]
//IntPtr Constructor (string fileName);
//[Export ("initByReferencingURL:")]
//IntPtr Constructor (NSUrl url);

// FIXME: need IconRec
//[Export ("initWithIconRef:")]
//IntPtr Constructor (IconRef iconRef);

[Export ("initByReferencingFile:"), Internal]
IntPtr InitByReferencingFile (string name);

[Export ("initWithPasteboard:")]
IntPtr Constructor (NSPasteboard pasteboard);

Expand Down