cocos2d error while loading sprite - iphone

I am having a quite strange problem in loading a sprite that was previously correctly loaded. I get this error depicted in the XCode console:
CCTexture2D. Can't create Texture. UIImage is nil
Couldn't add image:test.png in CCTextureCache
I can not see what is changed any advice?

Do you see test.png in the project navigator ? If yes, click on it, and make certain it is included in the target (show Utilities, at the top right, above the word 'view', the right button of that group of 3 buttons). Make certain that in the pane 'Target membership', your build target is selected. If not, well... you know what to do.
Also, as a 'personal rule', before trying anything when this sort of thing occurs, i tend to clean the target (including the project derived data), then a build and test again. Xcode can have its moments with respect to keeping track of files and stuff.

Make sure the file is named "test.png" and not "Test.png" because the iOS devices use a case-sensitive filesystem. The file also needs to be added to your Xcode project to the correct target.

Related

Xcode CUI Catalog bug

I am building a game in Xcode 10.0, using SpriteKit, and currently I don't have an AppIcon in my game. Everything works great.
When I add an icon, some assets "go missing".
What happens is in the console I get the message:
"CUICatalog: Invalid Request: requesting subtype without specifying idiom for asset named: "img_xxxxx""
And then these images appear with the white box and red cross, just as if they were missing.
Not all images go missing. The ones that go missing specifically are ones inside a .spriteatlas folder I have.
I've tried deleting this folder and putting it back in, doesn't work.
When I remove the icon and build again, the images reappear.
I've searched this bug along the web and to most people it's just a log issue, and their images still show up, but to me it's really annoying because these images stop showing up.
To anyone in the future:
- Remove and re-add an 'AppIcon' in the Assets.xcassets folder.
For some reason this will reset something in xcode and have your assets load again.
Experienced the same issue and this fixed it.

XCode buggily loading images that aren't in my project folder

For some reason, XCode is acting up really oddly. I have been testing XCode's ability to load images with the -hd suffix, and realized that Xcode will load a file "welcomeBackground.jpg" regardless of whether it is actually in my project folder.
See, this code below will not crash when compiled. And this is the first screen that is displayed when the app loads. I deleted the file "welcomeBackground.jpg" from my project folder, and XCode still loads the file as if it were there.
This is really freaking me out. Please help?
I am 200% sure I deleted the file from my project folder even and yet Xcode does not crash on line 35.
EDIT: To repeat, things I have tried/checked
- Cleaned project
- Deleted Derived Data
- Checked for hidden files in project folder
- Deleted app from iPhone and re-run from XCode
- Deleted the files from my project folder
- Loaded another image "sadhieia.png" and crashed Xcode
because Xcode couldn't find the file (as it does not
exist), and then tried "welcomeBackground.jpg" again
and Xcode somehow finds it.
And yet, the background still loads...
In Cocos2d, if the specified image is not in your folder, it'll not crash. Instead, it'll return nil to your CCSPrite *background.I suggest you Don't use Camelcase for images. Use lowercases or underscores. Try deleting Derived Data. See this for how to delete derived data.
Scroll the project navigator down to the bottom, to "Products," then click the disclosure arrow to show your application.
Right-click the application and choose "Show in Finder" from the contextual menu that appears. A Finder window is displayed containing your application.
Command-click the title of that window; another contextual menu appears. From that, choose the folder "Derived Data." The Finder then displays a window for that folder.
In this window, you'll see a folder whose name is that of your application, followed by a long string of letters. Trash it. If you see multiple folders bearing your application's name, trash them as well.
Rebuild your project. That should take care of the issue.
This might be a slash and burn approach, but it's solved a lot of quirky project-related issues I've experienced in Xcode after attempting to clean.
Clean your project; your image file is still cached in the build folder.

Why is app icon white?

Some recent version of iOS caused my app icon to turn white. I've gone through everything in regards to images and can't find the issue. I'm running Xcode 3.2.5 with sdk 4.2. I do have an entry for "Icon files" in Info.plist with 5 keys:
Item 0 myapp.png
Item 1 myapp#2x.png
Item 2 myapp-72.png
Item 3 myapp-Small-50.png
Item 4 myapp-Small.png
Item 5 myapp-Small#2x.png
All the above have proper dimensions.
I see the image in 'Copy Bundle Resources' and also in the .app file for the simulator version. It is properly reference by name in 'Icon files', Item 0. It is not named Default.png since it is referenced by name in Item 0.
Any suggestions?
You just need those 3 Files:
Icon.png
Icon#2x.png
Icon-iPad.png
Put the names into the Info.plist under Icon Files.
EDIT: Clean your target if it still won't work!
That is what helped me (project summary - app icons are ok, iOS simulator - app icons are ok, iPhone device - blank icon).
Just reconnect your icons to project by dragging them from project navigator to App icon section in project summary.
When does it turn white? If you upgrade an app when it's running, sometimes it appears with a white icon in the "task" bar. This applies to apps you're developing and those download from iTunes. The fix is usually just to kill the app and restart.
That's the simplest answer, but I suspect might not be the solution.
Does the case of the file names in your Info.plist match the actual file names? The Simulator is not case sensitive but the iOS is.
You might also like to make a completely clean build. Don't just do a "Clean" in Xcode, instead manually clear out your build folder.
Finally, when the iPhone 4 first came out I had some issues with the order of the icons referenced in the Info.plist. I never saw white icons (usually just the non-Retina version) but this may be something worth playing with if nothing else works.
The icon file name may be too long if it is a custom file name. This is just a guess, and I hate guessing, but this appears to have been the problem I just had.
I have four targets using the same code but with different icons. I named the icons differently based on the app name, so I could store them in the same directory.
For example:
Icon.png
Icon_second.png
Icon_alternate.png
Icon_second_alternate.png (or Icon_secondalternate.png in case underscores were an issue)
This nomenclature was used for all of the icon names (there's 8 icon files to support iPhone, iPad, retina, etc).
The last one was giving me a problem. Despite a hundred clean/rebuilds, deleting the schema entirely and creating a new one, fruitless efforts, it suddenly occurred to me to try renaming it.
You should be able to name the icons differently, as I still use the first three versions. They are listed in the plist file and render in the project summary, and on the simulator, just fine. The last one rendered in the summary as well. However, I think the length of the file name was too long for the simulator. There must be a length limit. I renamed the fourth one to use the standard Icon.png naming but added it to the fourth target only (images are stored in a separate folder).
CONCLUSION: If you have more than one target for your app, use the standard naming system for all of your icons but add them to separate folders, and then when adding to Xcode just set the build target appropriately.
If you still have the default icon entry (even blank), this can happen, remove that entry in info.plist.
Also, Default.png would be your splash screen.
Load the icons into the Preview application, and make sure they are really png format (and not just named such) by doing a "Save As..." specifying PNG format in the save dialog. Do a Get Info to check the sizes. Make sure the case of all letters in the name match your plist entries.
I had the same problem recently - the Icons I was using were created in GIMP. When I opened them in Photoshop on the development Mac it complained about an ICC color profile. After re-saving the PNGs in Photoshop the Icons worked like a treat.
P.s. I just repeated my steps in creating the images in GIMP, but when saving unticked every extra option that GIMP - by default - was trying to add into the image when saving it. The icons worked perfectly this time around.
If you believe your icon configuration is correct, then you may simply be seeing a bug in Xcode.
As a workaround…
"Clean" your project. Choose Xcode > Product > Clean.
Delete the app from your simulator, or even reset the Simulator by choosing iOS Simulator > Reset Content and Settings.
Quit both the iOS Simulator and XCode apps, then restart them.

Could not load the image referenced from a nib in the bundle running on device

SplitView[1290:307] Could not load the "canary04.png" image referenced from a nib in the bundle with identifier "xx.co.mycompany.ipad.SplitView"
I only get the error when running on the device. There are no problems running in simulator.
I am using the image directly in interface builder with an UIImageView.
EDIT: I have added a different new image to a different nib and that works no problems.
Anyone have any ideas?
It might not be added to your Target and in XCode 4 you can do it like this:
In your Project View, click your project name
Select your target and select "Build Phases" tab
Drag your image file into your "Copy Bundle Resources" section
That fixed it for me.
The filesystem on iOS devices is case sensitive, so it's quite possibly a case issue. (Mac OS X is generally case in-sensitive, hence you've not seen this issue in the simulator.)
As such, check that you're using the same case in the code as the filename itself.
Do you have the image in a referenced folder in XCode (blue folder)? If so you have to include the folder name in the image path, something like "Images/canary04.png"
The easy way
1 Simply do a grep in command shell to find the string of the referenced image:
grep -R 'canary04.png' YourMainDirectoryFolder/*
2 It will give you (for example) an output like this:
YourProject/en.lproj/YourViewController.xib:
<textField borderStyle="roundedRect" background="canary04.png" id="19">
3 You now know which nib file and which element it is. Just go in the file and remove the reference.
Delete the blue folder where the image is.
Import again and select "Copy items if needed".
Select "Create Groups" NOT folders
Save image as PNG-24. It works for me
You can do this to check it from your storyboard, or nib. Open it as Source Code:
Then "Find" the image name in it, see if it exists but already invalid in your project, probably you have deleted or changed its name, and now it doesn't seem valid.
Have you included the file in the target? Right-click on your Target in Xcode, select Get Info and choose the "Targets" group along the top. Make sure your intended target(s) are checked.
Good Luck.
EDIT:
The text above should have read Right-click the file (canary04.png) in Xcocde and select Get Info...
Sorry for the typo.
I had this problem when I upgraded to Xcode 4.4.1. I found that although I had deleted the images (and corresponding buttons, etc.) in the storyboards, there was still mention of them in my storyboard files (in a tabBarItems field). I manually commented them out (), Product -> Clean, and I didn't get the errors any more.
I knew there must be bogus references in the storyboard as I had previously deleted my TabBar and the current App worked without problems, just with annoying messages in the console.
I had the same issue. try to
clean
build and run
it worked with me
In my case, it was because Photoshop wasn't saving my files correctly. In the file save dialog I was clicking on myfile.png in an attempt to overwrite that file, and it was saving the file with a png extension, but in photoshop format.
I had to make sure to actually change the file format to PNG before clicking on the file I wanted to overwrite, thus saving in actual png file, thus being readable by iOS. Interestingly, interface builder showed my psd-as-png files just fine.
More generically, make sure your file is, in fact, in the format you think it is and that iOS is therefore expecting.
Solution 1 :
In my case I had copied folder containing images and even checked "Destination : copy items if needed". However it has not been added to "Copy Bundle Resources" of "Build Phases".
You can add images as follows :
Select Targets
Select "Build Phases" tab
Select "Copy Bundle Resources"
Click on "+" (Plus) button just beneath it
Locate images and add it
Solution 2 :
Delete images by selecting "Move to thrash". Again add images in your project with "Destination : copy items if needed" checked.
Note : Make sure that you add images in Assets.xcassets folder and not outside it.
I was getting this error too. I will describe my scenario:
I have a subdirectory "img" which has some png's in it.
One of these png is "ic_timeprogress_000.png"
In the storyboard (visual designer) I had an imageView and the image was set to "ic_timeprogress_000.png" (not programatically). The designer showed the imageView correctly:
Although when running the app, the error was thrown.
So in the storyboard I changed (I insist: not programatically) from "ic_timeprogress_000.png" to "img/ic_timeprogress_000.png", which lead to not showing correctly the image in the designer but showing correctly when running (no error)
Although I alter imageView.image programatically, so this "initial image" isn't ever used.
Check to make sure that canary04.png exists in your project, and that it was not deleted.
My problem was that I saved the image as .jpg and changed the name to .png (was still in jpg format). It worked with simulator
Check your image name. If it contains some spaces then image will show while running in simulator but not in the device. While running it checks Case sensitive name etc.
I had a different problem in iOS 8. In my case the problem was that I selected Device Specific for the image set, and then selected iPad. Changing this back to Universal fixed the problem.
This setting can be found in the images.xcassets file, in the third column show the attributes inspector for the image set.
In this case the images wont be displayed in the storyboard or NIB file even if you have added them to images.xcassets. They also wont show in the simulator or device.
I've encountered this issue when I was trying to set image of an imageView on Interface Builder (.xib) file.
(I was using Image Assets)
I've had 2 images with theImage.jpeg and theImage#2x.jpg
Interface Builder could be able to display true images at compile time with these jpg / jpeg formats. But I've got this error in the runtime:
Could not load the "theImage" image referenced from a nib in the bundle with identifier "org.etc.etc"
Then I changed my image files formats to .png and it worked!
Try this solution too if you have different formats for images you try to set.
I also met the problem that jpeg files cannot be loaded successfully, however I solved it without changing them to png format: for example, if you have an image named "bg.jpg", don't use "bg" in storyboard (this name is listed in the dropdown selection list), instead you should explicitly write "bg.jpg" in the name field.
For programming based image view, I guess using .jpg extension like [UIImage imageNamed:#"xx.jpg"] should also work (I did't test though).
Try cleaning the project and make sure the info.plist matches the xx.co.mycompany.ipad.SplitView
Check the image name. Then check to see if you can open the image itself in paint or photoshop. If the image was created in photoshop and there were layers sometimes there is some conflict with the .png
I had the same issue, if your images are inside sub-folders, you need to choose "Create groups for subfolders" Option when you copy the resources.
I have this problem with Xcode 5, and it seems "Combine high resolution artwork" is the culprit. I opened the app bundle, and all the images were *.tiff, which caused the image to "not be found" :S
FIX:
Open project settings, and search in the top for "combine". Change that setting to NO.
For some reason, everyone is missing this essential fix.
In my case all images where displaying fine on devices with >iOS 7 but not with iOS 6.1.
The solution was that iOS7 is case sensitive but iOS 6.1 wasn't for me. I had images named like "myImageName" and also named "myimagename" witch leads my old iPhone 3 to be unable to display these images.
So renaming them solved it.
Tried each and every answer here and nothing, so here's another glitch, your icon name cannot have dots (.) because if it does (and Xcode allows you to do that!) while the icons show well in storyboard, they won't load either in the simulator or the device.
Maybe after you set the button's image, you changed the image's name.
2015 - Still having this problem. I was referencing an image that no longer existed in one of tabbed buttons.
Solution:
Simply inspect all your buttons, UIImage etc. and make sure that the image that you are referencing actually exists within your project.
I got this problem when I accidentally added another Image set to Asset Catalog file. I renamed it after I realised the mistake, but it doesn't seem to work.
Removing the file and adding it again solves the problem.
what worked for me is making sure the file's owner in interface builder has a "view" outlet.
From IB, select file's owner from "Placeholders", then in "Connections Inspector" make sure the view outlet in connected to the main view of current XIB.
This happened because i removed the main view at some point and forgot to reconnect my new view.
Hope it helps somebody else.
In my case, the issue was the image format. They were 'jpg' files, while Xcode was expecting 'png' files. Changing the file format fixed the issue.

New Images Can't Be Found in iPhone SDK

I've been trying to update an image that is packaged with my app, but the app refuses to load the new file.
I originally had a png called "board.png". I then created a new file which is a higher resolution copy of the original. I deleted "board.png" from the Resources group in XCode and added the new image under the same name. When I run the app, the old, smaller image is still used.
Then, I cleaned the build and tried again. Still doesn't work. Next, I renamed the new image to "BigBoard.png" and tried loading that filename thusly:
UIImageView* board = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"BigBoard.png"]];
but the image does not load at all even though it is in the Resources folder. Does anyone else have any experience with this? Any help would be greatly appreciated.
Thanks!
I had the same problem twice now.
The first time I had just forgotten to check the 'Copy items into destination group's folder' option when I added the new image so the image want actually in the folder when I went to build.
The second time I needed to clean all targets (Build -> Clean All Targets) before I built again. This gets rid of all the precompiled stuff and forces xcode to completely recompile the project. When I did this the build results showed an extra action CopyPNGFile "path/to/image/image.png" so I think it was avoiding adding new image because it saw a precompiled version of it there already.
See if either of those fixes it.
I actually found the solution to this problem a little while ago. Since I converted my iPhone project into an iPad project, the new files I add to the project were not added automatically to the iPad target and would not be present in the iPad executable. To solve this problem, I had to manually add the files to the iPad target by right clicking the file -> Get Info -> Targets -> Check iPad target.
The recent XCode update also fixes this problem so you no longer have to manually add the targets.