David Morse
David Morse

Reputation: 41

Why wont SFML Xcode load my .png file using C++?

After finally being able to get SFML to work on Xcode, I have encountered another problem, that says my .png file cannot be loaded.

019-09-15 19:45:01.816739-0400 SFML Proj.[32379:2744427] MessageTracer: load_domain_whitelist_search_tree:73: Search tree file's format version number (0) is not supported
2019-09-15 19:45:01.816896-0400 SFML Proj.[32379:2744427] MessageTracer: Falling back to default whitelist
Failed to load image "res/img/mario.png". Reason: Unable to open file
Program ended with exit code: 9

This is the path to my file:

and this is what I put in for my file path for the texture:

sf::Texture texture;
texture.loadFromFile("res/img/mario.png");

can someone please help me?

Upvotes: 1

Views: 533

Answers (1)

Indiana Kernick
Indiana Kernick

Reputation: 5341

In project settings, under the build phases tab, create a new "Copy Bundle Resources" build phase (if there isn't one already). Build phases are things that happen while the bundle is being built. "Copy Bundle Resources" copies files into the Resources folder of the bundle.

screenshot

Copy ResourcePath.hpp and ResourcePath.mm into your project. The resourcePath() function returns the path to the resources folder in the bundle.

sf::Texture texture;
texture.loadFromFile(resourcePath() + "mario.png");

To verify that the file is in the bundle, find the bundle...

screenshot

then open the bundle...

screenshot

For more information, see the tutorial.

Upvotes: 1

Related Questions