Hello!
I am trying to make a game in SDL on my new Mac using Xcode and with that, I have imported SDL2_Image to use to load images. Everything was going well, I was able to include the header files with no issues and even initialize it, but when it came time to giving a path to pull an image from, that’s where I got errors.
Unable to load image! Img_Error: Couldn't open [insert path here]: Operation not permitted
Keep in mind that “Unable to load image!” Is what I’ve coded in for the case that an error occurred, this is different from tine img_error that I Called with IMG_GetError() if that makes sense.
I am using:
SDL2
Xcode on Mac
SDL2_Image
What exactly is [insert path here]
and what file permissions does it have?
[Insert path here] is a path to a sprite. As for permissions, my user account > Read & Write access, Staff > Read & Write access, Everyone > Read & Write access
Can you tell me where in the filesystem the file is located though?
How are you running your game process?
The most likely cause of the issue is file/directory permissions and I am trying to help you figure out the reason.
The sprites are located within the project
MainProjectFolder > SubProjectFolder (Main.cpp is located here) > SubProjectFolder > SpriteFolder > SubSpriteFolder > sprite.png
I am running the game within Xcode
So you are building a macOS app bundle? First thing to check is the structure of the app bundle itself; that’s in ~/Library/Developer/Xcode/DerivedData/ProjectM_v0.1.0-(someletters)/Build/Products
.
Now check the app bundle is correct and that Sprites
are part of ProjectM_v0.1.0/Contents/Resources
.
It’s not clear to me why you’ve put the version in the product name; that is very unusual.
Anyway if the resources are in the app bundle the next thing to check is how you are locating them at runtime, which you will need to do via the NSBundle
APIs.
Sorry for the wait, I was at school and unable to respond.
But yes, when I checked the resources of the program, I saw all the contents. But the thing is, the sprites folder wasn’t in it. It was just all the contents of the sprite folder itself. I decided to copy the path of said sprite and paste that into the code and see if it would run. Tada! it works. I think that I can try to find this out on my own now and go on from here.
But thank you very much, you were a big help!
OK glad you got it sorted; to have Xcode copy files into the Resources
folder you just need to add the folder to Xcode; however you need to add a folder reference so that you can update the source contents without having to make changes to the Xcode project.
1 Like