SFML community forums

Help => General => Topic started by: mperic on March 30, 2022, 06:24:10 pm

Title: loadFromFile() randomly fails
Post by: mperic on March 30, 2022, 06:24:10 pm
Hi.

I am using SFML for the graphics of an ant simulation, and I am loading textures and fonts using loadFromFile(). All of these loadFromFile() calls are happening under one iteration of a loop, and when the simulation ends, the loop restarts, and loadFromFile() is called again. This works fine, but after about 3-5 hours of the loop restarting (one iteration of the loop takes appoximately 30 minutes) some of my textures won't load. And then usually, the next iteration will have no textures load.

Any idea why this may be happening?

I suspect that there may be some kind of problems occurring with file buffers since I am not closing the streams at the end of each iteration/

Is there any way to close the loadFromFile() file streams manually? Is there another possible problem here?

Thanks,
mperic
Title: Re: loadFromFile() randomly fails
Post by: eXpl0it3r on March 30, 2022, 07:11:29 pm
Why would you be reloading textures and fonts hours on end?

Since you mention streams, are you calling loadFromFile or loadFromStream?
Title: Re: loadFromFile() randomly fails
Post by: mperic on March 30, 2022, 09:01:59 pm
I am calling loadFromFile().

Why would you be reloading textures and fonts hours on end?

This was forked from another repository, and I don't think it was ever intended to be restarted like this. Now that you mention it, I do have a centralized text-manager struct that I could use, as it only loads fonts and textures once. However, I do have map loading which would be reloaded repeatedly. I would have to find a way to pre-load the maps accordingly.

I suppose it would be advisable to load everything once rather than reloading it repeatedly.  ;) Thanks for your response.