🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #1653

Developer Support "core dump": NXImage question

#1653
From: Julie Zelenski
Date: Tue, 29 Sep 1992 19:25
60 lines
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
Technical Details
Message-ID: <5201@rosie.NeXT.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!ames!olivea!decwrl!rosie!next.com

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!ames!olivea!decwrl!rosie!next.com
From: julie@next.com (Julie Zelenski)
Newsgroups: comp.sys.next.programmer
Subject: Developer Support "core dump":  NXImage question
Keywords: NXImage seg fault
Message-ID: <5201@rosie.NeXT.COM>
Date: 29 Sep 92 19:25:12 GMT
Sender: news@NeXT.COM
Reply-To: julie@next.com
Lines: 60