Thread View: comp.sys.next.programmer
3 messages
3 total messages
Started by Julie Zelenski
Tue, 29 Sep 1992 19:25
Developer Support "core dump": NXImage question
Author: Julie Zelenski
Date: Tue, 29 Sep 1992 19:25
Date: Tue, 29 Sep 1992 19:25
60 lines
3183 bytes
3183 bytes
A developer recently asked, "I have encountered difficulty in working with the ButtonCell class and (firmly) believe it may be a bug in NeXT's appkit. I have set my ButtonCell to display a certain image using setIcon:. Later I will change the image and I want to free the original image. No problem occurs at the time you free the image, but the behavior of the program is unpredictable after that point and it is prone to crashing upon sending the display message to the view containing my ButtonCell. The backtrace ends with a failed call to objc_msgSend(). There is a very remote chance that this is not an appkit bug and that it may be a logic error in my code. However, I have traced this bug for a couple of weeks and have simplified my program dramatically in an effort to remove it. The only thing that worked was to remove the lines where I free the image. Have you had any reports on this problem in the past?" Your trusty developer support engineer often starts with the docs. The method description for setIcon: in ButtonCell pointed her to the method findImageNamed: in NXImage class. The intro to NXImage describes how it manages a class database of named images. NXImage is a smart enough beast to create only one instance of a named image and share it across the application. Her best guess at this problem was that the image being freed was a shared image. Although his button cell was no longer needed it, some other object still was using it. To test her theory, she wrote a small example with two buttons. Both buttons used the same image. She set the image to nil in one of the buttons and free its image. Clicking on the other button crashed with the following backtrace: Program generated(1): Memory access exception on address 0x20 (protection failure). #0 0x50069be in objc_msgSend () #1 0x6012e16 in - [ButtonCell _getIconInfo:] #2 0x6015dc6 in - [ButtonCell _getIconRect:flipped:] #3 0x60161d4 in - [ButtonCell _getIconRect:andTitleRect:flipped:] #4 0x6015480 in - [ButtonCell drawInside:inView:] #5 0x60167c2 in - [ButtonCell drawSelf:inView:] #6 0x6028422 in - [ButtonCell highlight:inView:lit:] #7 0x60309ca in - [Control mouseDown:] #8 0x60190aa in - [Window sendEvent:] #9 0x6014362 in - [Application sendEvent:] #10 0x6036efe in - [Application run] #11 0x31fa in main (argc=1, argv=(char **) 0x3fffcd4) (test_main.m line 11) Just like the backtrace the developer was experiencing. What's the moral of the story? Be careful with named images. If you name an NXImage with setName: or retrieve it by way of findImageNamed:, be sure it isn't use by someone else if you free it. Julie Zelenski julie@next.com Developer Support
Re: Developer Support "core dump": NXImage question (a better answer?)
Author: Paul Burchard
Date: Wed, 30 Sep 1992 00:52
Date: Wed, 30 Sep 1992 00:52
33 lines
2347 bytes
2347 bytes
In article <5201@rosie.NeXT.COM> julie@next.com (Julie Zelenski) writes:
>
> A developer recently asked,
>
> "I have encountered difficulty in working with the ButtonCell class and
> (firmly) believe it may be a bug in NeXT's appkit.
>
> I have set my ButtonCell to display a certain image using setIcon:. Later
> I will change the image and I want to free the original image. No problem
> occurs at the time you free the image, but the behavior of the program is
> unpredictable after that point and it is prone to crashing upon sending
> the display message to the view containing my ButtonCell. The backtrace
> ends with a failed call to objc_msgSend().
>
By chance I was investigating *exactly* this problem today. I was having this problem despite making sure that this was NOT a shared image with any other part of the program, and further, I had been careful to FIRST change the cell's icon and THEN free the old one (in case -setIcon: somehow needs to "deinstall" the old icon):
[cell setIcon:newIconName];
[[NXImage findImageNamed:oldIconName] free]; //!!! still flaky
Nevertheless I still had the problem. My conclusion was that *somewhere* in the bowels of the AppKit, a pointer to the old icon was still being cached. So to flush out any display caches I triggered an update before freeing the image:
[cell setIcon:newIconName]; // cell == self->cell
[self update]; // make sure image references flushed out of system!
[[NXImage findImageNamed:oldIconName] free]; // OK!
This now appears to work.
--
--------------------------------------------------------------------
Paul Burchard <burchard@geom.utah.edu>
``I'm still learning how to count backwards from infinity...''
--------------------------------------------------------------------
Re: Developer Support "core dump": NXImage question
Author: Paul Burchard
Date: Wed, 30 Sep 1992 00:59
Date: Wed, 30 Sep 1992 00:59
58 lines
3998 bytes
3998 bytes
P.S. Glad to see NeXT out here with us! For inspiration, check out
comp.sys.sgi to see what a positive effect active and informative participation by company volunteers can have...
--
--------------------------------------------------------------------
Paul Burchard <burchard@geom.umn.edu>
``I'm still learning how to count backwards from infinity...''
--------------------------------------------------------------------
-------------------------------------
Paul Burchard <burcha was having this problem despite making sure that this was NOT a shared image with any other part of the program, and further, I had been careful to FIRST change the cell's icon and THEN free the old one (in case -setIcon: somehow needs to "deinstall" the old icon):
[cell setIcon:newIconName];
[[NXImage findImageNamed:oldIconName] free]; //!!! still flaky
Nevertheless I still had the problem. My conclusion was that *somewhere* in the bowels of the AppKit, a pointer to the old icon was still being cachrd@geom.umn.edu>
``I'm still learning how to count backwards from infinity...''
--------------------------------------------------------------------
-------------------------------------
Paul Burchard <burcha was having this problem despite making sure that this was NOT a shared image with any other part of the program, and further, I had been careful to FIRST change the cell's icon and THEN free the old one (in case -setIcon: somehow needs to "deinstall" the old icon):
[cell setIcon:newIconName];
[[NXImage findImageNamed:oldIconName] free]; //!!! still flaky
Nevertheless I still had the problem. My conclusion was that *somewhere* in the bowels of the AppKit, a pointer to the old icon was still being cached. So to flush out any display caches I triggered an update before freeing the image:
[cell setIcon:newIconName]; // cell == self->cell
[self update]; // make sure image references flushed out of system!
[[NXImage findImageNamed:oldIconName] free]; // OK!
This now appears to work.
--
--------------------------------------------------------------------
Paul Burchard <burchard@geom.utah.edu>
``I'm still learning how to count backwards from infinity...''
-----------rd@geom.umn.edu>
``I'm still learning how to count backwards from infinity...''
--------------------------------------------------------------------
-------------------------------------
Paul Burchard <burcha was having this problem despite making sure that this was NOT a shared image with any other part of the program, and further, I had been careful to FIRST change the cell's icon and THEN free the old one (in case -setIcon: somehow needs to "deinstall" the old icon):
[cell setIcon:newIconName];
[[NXImage findImageNamed:oldIconName] free]; //!!! still flaky
Nevertheless I still had the problem. My conclusion was that *somewhere* in the bowels of the AppKit, a pointer to the old icon was still being cached. So to flush out any display caches I triggered an update before freeing the image:
[cell setIcon:newIconName]; // cell == self->cell
[self update]; // make sure image references flushed out of system!
[[NXImage findImageNamed:oldIconName] free]; // OK!
This now appears to work.
--
--------------------------------------------------------------------
Paul Burchard <burchard@geom.utah.edu>
``I'm still learning how to count backwards from infinity...''
-----------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads