Re: Questions regarding release

2019-09-25 Thread Quincey Morris via Cocoa-dev
On Sep 25, 2019, at 13:52 , Rob Petrovec via Cocoa-dev 
 wrote:
> 
>> Is the IOObjectRelease() right or wrong ?
>   I’m not entirely sure since I can’t find the docs for 
> IOServicePortFromCGDisplayID.

Given that the code fragment shows it as a message being sent to “self”, this 
looks like Gabriel’s own method. By the standard Obj-C clang naming 
conventions, this should return a non-owning (+0) reference, so it should not 
be released without being explicitly retained.

My guess is that it actually returns a +1 reference, but uses a non-standard 
naming convention. In that case, the code is correct as written (although 
unclear because it doesn’t follow the naming conventions).

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Confusion about release mode in Xcode

2019-09-25 Thread Quincey Morris via Cocoa-dev
On Sep 25, 2019, at 14:44 , Gabriel Zachmann via Cocoa-dev 
 wrote:
> 
> I have tried to create a new scheme, then changed the Build Configuration to 
> "Release".
> But in
>  Build Phases ⟶ Copy Files 
> it still says that the product is copied from ... build/Debug.
> (The destination is /Users/home/Library/Screen Savers)
> I have deleted it and added it to the Copy Files phase again, same result.

Assuming that you’re copying an item that is listed in the navigator pane, then 
the correct thing to do is to select it in the navigator, show the File 
inspector, and change the Location popup to “Relative to Build Products”.

However, if this is the Products group, when I looked at a project of mine, 
Xcode 11 doesn’t let me change that popup — it’s already locked to “Relative to 
Build Products”. So, I’m not sure if there’s something else going on here.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Questions regarding release

2019-09-25 Thread Rob Petrovec via Cocoa-dev


> On Sep 25, 2019, at 2:52 PM, Rob Petrovec via Cocoa-dev 
>  wrote:
> 
>> Is it safe to do it after assigning the nsimage to the layer, but before 
>> deleting the layer?
>   I would think so, but it is hard to say without knowing what 
> convertToNSImage:withOrientation actually does under the hood.  It likely 
> either retains or copies it.  In either case, your release is safe & correct.
With that said, CALayer.contents will convert the NSImage into a 
CGImageRef under the hood.  So even your NSImage won’t live for very long.

—Rob


>> Is the IOObjectRelease() right or wrong ?
>   I’m not entirely sure since I can’t find the docs for 
> IOServicePortFromCGDisplayID.  But just from the name of 
> IODisplayCreateInfoDictionary alone, info needs to be released via 
> CFRelease(info).
> 
> —Rob
> 
> 
>> On Sep 25, 2019, at 1:31 PM, Gabriel Zachmann via Cocoa-dev 
>>  wrote:
>> 
>> A few years ago, I switched my code to ARC.
>> 
>> Now, I have this in my code:
>> 
>>   CGImageRef imageRef = CGImageSourceCreateImageAtIndex( sourceRef, 0, NULL 
>> );
>>   ...
>>  NSImage * nsimage = [self convertToNSImage: img withOrientation: 
>> img_orientation];
>>assign nsimage to a layer
>>   ...
>>   CGImageRelease( imageRef );
>>   ...
>>   use the layer with the nsimage
>> 
>> The doc for CGImageSourceCreateImageAtIndex() that I need to release 
>> imageRef myself.
>> Is it safe to do it after assigning the nsimage to the layer, but before 
>> deleting the layer?
>> Or should I keep the imageRef until the layer itself gets removed from its 
>> super layer?
>> 
>> 
>> Also, I have some more release's in my code, and I would appreciate your 
>> advice 
>> whether or not I still need them.  (Sometimes, I still get confused.)
>> 
>>   io_service_t serv = [self IOServicePortFromCGDisplayID: displayID];
>>   CFDictionaryRef info = IODisplayCreateInfoDictionary(serv, 
>> kIODisplayOnlyPreferredName);
>>   IOObjectRelease(serv);
>> 
>> Is the IOObjectRelease() right or wrong ?
>> 
>> 
>> Thanks a lot in advance.
>> 
>> Best regards, Gabriel
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/petrock%40mac.com
>> 
>> This email sent to petr...@mac.com
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/petrock%40mac.com
> 
> This email sent to petr...@mac.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Confusion about release mode in Xcode

2019-09-25 Thread Gabriel Zachmann via Cocoa-dev
I haven't released my software (screensaver) in many years,
so please bear with me, I am not up-to-date any more how this works.

I have tried to create a new scheme, then changed the Build Configuration to 
"Release".
But in
  Build Phases ⟶ Copy Files 
it still says that the product is copied from ... build/Debug.
(The destination is /Users/home/Library/Screen Savers)
I have deleted it and added it to the Copy Files phase again, same result.

On the other hand, when I check /Users/home/Library/Screen 
Savers/ArtSaver.saver/Contents/MacOS/ ,
the executable has the right timestamp , and it's file size is slightly less 
than the size of the exec 
in .../Build/Products/Release/ArtSaver.saver/Contents/MacOS .

So , I am confused.

I have also tried Product ⟶ Archive, which was recommended on the internet, but 
then I got this error message:
Multiple commands produce 
'/tmp/ArtSaver-hcwtwqkubldekzfijehvpaeowamp/Build/Intermediates.noindex/ArchiveIntermediates/ArtSaver/InstallationBuildProductsLocation/Users/zach/Library/Screen
 Savers/ArtSaver.saver':
1) Target 'ArtSaver' has create directory command with output 
'/tmp/ArtSaver-hcwtwqkubldekzfijehvpaeowamp/Build/Intermediates.noindex/ArchiveIntermediates/ArtSaver/InstallationBuildProductsLocation/Users/zach/Library/Screen
 Savers/ArtSaver.saver'
2) Target 'ArtSaver' has copy command from 
'/tmp/ArtSaver-hcwtwqkubldekzfijehvpaeowamp/Build/Intermediates.noindex/ArchiveIntermediates/ArtSaver/BuildProductsPath/Release/ArtSaver.saver'
 to 
'/tmp/ArtSaver-hcwtwqkubldekzfijehvpaeowamp/Build/Intermediates.noindex/ArchiveIntermediates/ArtSaver/InstallationBuildProductsLocation/Users/zach/Library/Screen
 Savers/ArtSaver.saver'

Of course, I tried to find a solution by googling, again to no avail.


I just want to build a release version of my code, with the usual settings, 
such as -O3 (or -Os) and stripped debug symbols.
I am fine with copying that out of whatever directory it will end up in.

All hints and pointers will be appreciated.
Thanks a lot in advance for all kinds of insights.

Best regards, Gabriel




smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Questions regarding release

2019-09-25 Thread Wim Lewis via Cocoa-dev



On Sep 25, 2019, at 12:31 PM, Gabriel Zachmann via Cocoa-dev 
 wrote:
> The doc for CGImageSourceCreateImageAtIndex() that I need to release imageRef 
> myself.
> Is it safe to do it after assigning the nsimage to the layer, but before 
> deleting the layer?

Yes, the NSImage will retain/release the image ref if it needs to keep using 
it, and the layer will retain/release the NSImage if it needs to, so that you 
don't have to worry about the exact lifetime of the CGImage or NSImage. 

As for IOObjectRelease(), the usual rule of thumb is that ARC takes care of 
ObjC retain-release but you still need to do C (CoreFoundation, etc) management 
yourself; I suppose it depends on the implementation of 
IOServicePortFromCGDisplayID: whether it expects you to release the returned 
io_service_t or not, but ARC shouldn't be doing any automatic releasing of that 
variable, since it's a mach-port and not an object.

The Xcode "analyze" step should check for errors of this kind. I have xcode set 
to analyze on every build, since it's usually not too slow.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Questions regarding release

2019-09-25 Thread Rob Petrovec via Cocoa-dev
> Is it safe to do it after assigning the nsimage to the layer, but before 
> deleting the layer?
I would think so, but it is hard to say without knowing what 
convertToNSImage:withOrientation actually does under the hood.  It likely 
either retains or copies it.  In either case, your release is safe & correct.

> Is the IOObjectRelease() right or wrong ?
I’m not entirely sure since I can’t find the docs for 
IOServicePortFromCGDisplayID.  But just from the name of 
IODisplayCreateInfoDictionary alone, info needs to be released via 
CFRelease(info).

—Rob


> On Sep 25, 2019, at 1:31 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> A few years ago, I switched my code to ARC.
> 
> Now, I have this in my code:
> 
>CGImageRef imageRef = CGImageSourceCreateImageAtIndex( sourceRef, 0, NULL 
> );
>...
>   NSImage * nsimage = [self convertToNSImage: img withOrientation: 
> img_orientation];
> assign nsimage to a layer
>...
>CGImageRelease( imageRef );
>...
>use the layer with the nsimage
> 
> The doc for CGImageSourceCreateImageAtIndex() that I need to release imageRef 
> myself.
> Is it safe to do it after assigning the nsimage to the layer, but before 
> deleting the layer?
> Or should I keep the imageRef until the layer itself gets removed from its 
> super layer?
> 
> 
> Also, I have some more release's in my code, and I would appreciate your 
> advice 
> whether or not I still need them.  (Sometimes, I still get confused.)
> 
>io_service_t serv = [self IOServicePortFromCGDisplayID: displayID];
>CFDictionaryRef info = IODisplayCreateInfoDictionary(serv, 
> kIODisplayOnlyPreferredName);
>IOObjectRelease(serv);
> 
> Is the IOObjectRelease() right or wrong ?
> 
> 
> Thanks a lot in advance.
> 
> Best regards, Gabriel
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/petrock%40mac.com
> 
> This email sent to petr...@mac.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Questions regarding release

2019-09-25 Thread Gabriel Zachmann via Cocoa-dev
A few years ago, I switched my code to ARC.

Now, I have this in my code:

CGImageRef imageRef = CGImageSourceCreateImageAtIndex( sourceRef, 0, NULL );
...
   NSImage * nsimage = [self convertToNSImage: img withOrientation: 
img_orientation];
 assign nsimage to a layer
...
CGImageRelease( imageRef );
...
use the layer with the nsimage

The doc for CGImageSourceCreateImageAtIndex() that I need to release imageRef 
myself.
Is it safe to do it after assigning the nsimage to the layer, but before 
deleting the layer?
Or should I keep the imageRef until the layer itself gets removed from its 
super layer?


Also, I have some more release's in my code, and I would appreciate your advice 
whether or not I still need them.  (Sometimes, I still get confused.)

io_service_t serv = [self IOServicePortFromCGDisplayID: displayID];
CFDictionaryRef info = IODisplayCreateInfoDictionary(serv, 
kIODisplayOnlyPreferredName);
IOObjectRelease(serv);

Is the IOObjectRelease() right or wrong ?


Thanks a lot in advance.

Best regards, Gabriel




smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSMenuItem : acceptsFirstMouse(forEvent: NSEvent)

2019-09-25 Thread Mark Wade via Cocoa-dev
Had to override acceptsFirstMouse in NSDatePicker not NSMenuItem. Works, still 
doesn’t highlight the fields when selected but works. Guess I’ll figure it out.

Would like to know what is different when run directly and when run from Xcode 
though

> On Sep 24, 2019, at 1:23 PM, Mark Wade via Cocoa-dev 
>  wrote:
> 
> Hi All,
> 
> I’m at a loss here.  I’ve created a statusbar item, using Swift 5, whose 
> first menu item is a textwithstepper NSDatePicker which I created by setting 
> the menu item’s view. This all works fine when run from within XCode.  
> Running the app directly still works, however I can’t select the fields to 
> change with the stepper, why it works in Xcode and not without I don’t know. 
> So, I’m thinking I have to implement acceptsFirstMouse(for event:) to return 
> true, I think.
> 
> I’ve subclassed NSMenuItem and overridden acceptsFirstMouse( for event:) but 
> then how do I add the NSDatePicker? I can’t override the NSMenuItem view 
> variable, if I set the view to my subclass and then set the view to the 
> datepicker, it’s not my subclass anymore. I’ve been over and over this and 
> I’m just not getting it.
> 
> A clue, a pointer, an example, anything would be appreciated.
> 
> — Mark


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


How to have users select a directory

2019-09-25 Thread Gabriel Zachmann via Cocoa-dev
I am looking for a nice, intuitive way to let users select a directory.

Right now, I have a simple TextField in my GUI that shows the current path,
and a simple Button next to it that says "Change".
When users click on it, it opens an NSOpenPanel that is runModal.

This works fine, but I am wondering if there are more elegant methods.
For instance, whether it might be possible to dispense with the button,
make it obvious that users can click on the text field, and then open the 
NSOpenPanel.

Or are there any other neat ideas?

(I was stumbling across NSPathControl, but it is not clear to me whether that 
would be a good alternative,
and how difficult it might be.)

Thanks a lot in advance for all kinds of insights and hints.

Best regards, Gabriel




smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CGImageSourceCopyPropertiesAtIndex fails sometimes

2019-09-25 Thread Gary L. Wade via Cocoa-dev
I don’t recall if the URL can be a remote URL in addition to a file URL, but 
regardless, check the status of the source ref with CGImageSourceStatus first. 
The index value is used for compound images like animated GIFs and PNGs.
--
Gary L. Wade
http://www.garywade.com/

> On Sep 25, 2019, at 8:10 AM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> 
> I have this piece of code in my program:
> 
>CGImageSourceRef sourceRef = CGImageSourceCreateWithURL( (CFURLRef) url, 
> NULL );
>if ( sourceRef == NULL )
>{
>... display error message 1
>return;
>}
>CFDictionaryRef fileProps = CGImageSourceCopyPropertiesAtIndex( sourceRef, 
> 0, NULL );
>if ( ! fileProps )
>{
>... display error message 2
>return;
>}
> 
> Now, occasionally, I get "error message 2" but not "error message 1",
> i.e.,  CGImageSourceCopyPropertiesAtIndex() apparently fails, while 
> CGImageSourceCreateWithURL() retuned a valid(?) image source ref.
> 
> I am wondering, how this could happen.  Does anyone have a clue?
> 
> Furthermore, when I run the program a few minutes later, without any changes 
> whatsoever, 
> both function calls work just fine, with the same image files!
> 
> 
> Puzzled, Gabriel.
> 
> PS:
> I never understood what the index in CGImageSourceCopyPropertiesAtIndex() is 
> meant for,
> and I could not find a clue in the docs, and every example uses just 0 ‒
> but probably, this is not related to the problem described above.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


CGImageSourceCopyPropertiesAtIndex fails sometimes

2019-09-25 Thread Gabriel Zachmann via Cocoa-dev

I have this piece of code in my program:

CGImageSourceRef sourceRef = CGImageSourceCreateWithURL( (CFURLRef) url, 
NULL );
if ( sourceRef == NULL )
{
... display error message 1
return;
}
CFDictionaryRef fileProps = CGImageSourceCopyPropertiesAtIndex( sourceRef, 
0, NULL );
if ( ! fileProps )
{
... display error message 2
return;
}

Now, occasionally, I get "error message 2" but not "error message 1",
i.e.,  CGImageSourceCopyPropertiesAtIndex() apparently fails, while 
CGImageSourceCreateWithURL() retuned a valid(?) image source ref.

I am wondering, how this could happen.  Does anyone have a clue?

Furthermore, when I run the program a few minutes later, without any changes 
whatsoever, 
both function calls work just fine, with the same image files!


Puzzled, Gabriel.

PS:
I never understood what the index in CGImageSourceCopyPropertiesAtIndex() is 
meant for,
and I could not find a clue in the docs, and every example uses just 0 ‒
but probably, this is not related to the problem described above.




smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com