Re: Question about UIElementRefs
Re: Question about UIElementRefs
- Subject: Re: Question about UIElementRefs
- From: John Louch <email@hidden>
- Date: Wed, 26 Nov 2003 10:08:10 -0800
>
on 2003-11-26 9:09 AM, Andrew Taylor at email@hidden wrote:
>
>
> My program caches UIElementRefs for windows that it has notifiers
>
> for. Upon occasion, the program will do a CFEqual to determine if two
>
> UIElementRefs are equal, and it will crash inside CFEqual. I think
>
> this typically occurs after a window has closed and my program does
>
> not know it yet (once it does, cached values are zeroed). I know that
>
> the UIElementRefs are NOT zero, the program checks the arguments for
>
> nonzero before calling CFEqual.
>
>
I discussed this issue at length with the Apple engineers about a year ago.
>
The consensus was that the only safe way to handle this issue is to register
>
for the element-destroyed notification for every UIElementRef you create. I
>
do this in PreFab UI Browser, and it works like a charm.
That9s a different problem Bill. Andrew's issue is that he is using a
object that has been either over-released or over-written. This is causing
his app to crash when he calls CFEqual on the object.
>
>
The code isn't really too complex. Whenever I create a UIElementRef that I
>
intend to keep around, I also create an observer and register it for the
>
element-destroyed notification. I have a callback function that is dedicated
>
to handling the receipt of this notification and no other. This
>
special-purpose callback function simply sets a variable that is associated
>
with this UIElementRef to mark it as destroyed, and I always check the
>
variable before attempting to do anything with the UIElementRef.
>
>
UIElementRefs for destroyed elements (like closed windows) can contain
>
either garbage, or real UIElementRef data for SOME OTHER ELEMENT. So you
>
won't always crash if you don't take these precautions, but you will almost
>
certainly get bad data.
A UIElementRef never contains "garbage", it contains a representation of the
object that was destroyed which is comparable with a cached object pointing
to the same element. Trying to work with an element that no longer exists
in the application that you are communicating with should never crash either
your app or the other. You will get errors back from the AX API when you
try to use these elements though.
Thanks,
jl
>
>
--
>
>
Bill Cheeseman - email@hidden
>
Quechee Software, Quechee, Vermont, USA
>
http://www.quecheesoftware.com
>
>
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
>
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
>
_______________________________________________
>
accessibility-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/accessibility-dev
>
Do not post admin requests to the list. They will be ignored.
--------------------------------------------------
John Louch Internet #: email@hidden
(805) 546 0216
_______________________________________________
accessibility-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/accessibility-dev
Do not post admin requests to the list. They will be ignored.