Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > strange NSImage behavior?

strange NSImage behavior?
Thread Tools
Dedicated MacNNer
Join Date: May 2003
Location: Atlanta, GA
Status: Offline
Reply With Quote
Sep 10, 2003, 09:42 PM
 
Here's a tough one for you...

I'm loading images in my game as follows:

fImage[0] = [NSImage imageNamed:@"block1"];
fImage[1] = [NSImage imageNamed:@"block2"];
fImage[2] = [NSImage imageNamed:@"block3"];
fImage[3] = [NSImage imageNamed:@"block4"];
fImage[4] = [NSImage imageNamed:@"block5"];
fImage[5] = [NSImage imageNamed:@"sblocka"];
fImage[6] = [NSImage imageNamed:@"sblockc"];
fImage[7] = [NSImage imageNamed:@"sblockn"];
fImage[8] = [NSImage imageNamed:@"sblockr"];
fImage[9] = [NSImage imageNamed:@"sblocks"];
fImage[10] = [NSImage imageNamed:@"sblockb"];
fImage[11] = [NSImage imageNamed:@"sblockg"];
fImage[12] = [NSImage imageNamed:@"sblockq"];
fImage[13] = [NSImage imageNamed:@"sblocko"];

where fImage is defined in the interface as :

NSImage *fImage[14];

These images are tiff files stored in an images folder/group that IS getting properly bound/copied into the app bundle at compile time (I looked).

I'm doing it the long way for a reason, but I'm open to suggestions to simplify

Now, on to my question. block1-block5 work fine. I can draw w/ them all day long. The sblock series will ONLY load/draw correctly if I'm running my app in the debugger. At normal runtime the image draws in blank (no loading errors or anything like that spit out, runs fine just draws transparent).

These images are all derived from the same photoshop file, the only thing that changes is the background color layer (the sblocks also have a letter on them).

So, any ideas? All help is GREATLY appreciated
Alex

G7 Software: home Tetrinet Aqua
-----
"Utopia" 1Ghz TiBook SuperDrive w/ 1Gb RAM.
     
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status: Offline
Reply With Quote
Sep 11, 2003, 10:58 AM
 
Since you don't do alloc or copy on the NSImage instances, you need to retain them.

fImage[x] = [[NSImage imageNamed:@"foo"] retain];

Remember to release the images in the array once you're done with them. This is a good article that describes memory management in Cocoa.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2