Thanks for responding Laurent.
As I wrote as a comment in the last snippet
Cpt is a typedef for char*
so its just a pointer to a
bunch of chars that's freed after being passed to the
sf::Image.LoadFromFile function as the image file name.
I'll try to make the problem it a little bit clearer
While this code runs without any problems, that means no crash and
the image is displayed correctly:
#include <SFML/Graphics.hpp>
int main()
{
RenderWindow window(...);
Image img = General::LoadIMG("myIMG.png");
Sprite spr(img);
//Main Loop
window.Clear(...);
window.Draw(spr);
window.Display(...);
return 0;
}
This one is going to crash although only the Rotate() call is added:
#include <SFML/Graphics.hpp>
int main()
{
RenderWindow window(...);
Image img = General::LoadIMG("myIMG.png");
Sprite spr(img);
spr.Rotate(0.5f); //Rotate the sprite.
//Main Loop
window.Clear(...);
window.Draw(spr);
window.Display(...);
return 0;
}
But since doing this replacement fixes the error
(i.e. it then does show up AND rotate):
{ Image img = General::LoadIMG("myIMG.png"); }
becomes...
{ Image img; img.LoadFromFile("myIMG.png"); }
It means that this function
sf::Image General::LoadIMG(Cpt _file)
{
sf::Image img;
if(!img.LoadFromFile(_file))
std::cout << lend;
delete _file;
return img;
}
needs to be causing a crash whenever i call a method associated with the sprite's rotation.
But the strange thing is that - as you can see in the first snippet of this post - i'm able to render the image loaded by my wrapped function,
while rotating doesnt work? that would mean it does only partially load the image which sounds pretty unlikely...:/
So here's a complete (as minimal as possible
) file.
I've moved the img loading function in there for maximal minimality^^
#include <SFML/Graphics.hpp>
#include <iostream>
#define lend std::endl
using namespace sf;
Image LoadIMG(char *_file)
{
Image img;
if(!img.LoadFromFile(_file))
std::cout << lend;
delete _file;
return img;
}
int main()
{
RenderWindow window(VideoMode(1280, 640, 32), "Caption goes here");
Event event;
Image img = LoadIMG("myIMG.png");
Sprite spr(img);
spr.Rotate(0.5f); //!Runs without this line and crashes with!
while(window.IsOpened())
{
while(window.GetEvent(event))
{
switch(event.Type)
{
case event.Closed:
window.Close();
break;
}
}
window.Clear();
window.Draw(spr);
window.Display();
}
return 0;
}
This snippet does always crash on my system and if i remove the spr.Rotate(0.5f); line it does draw the sprite without complaints <.<
I really don't know why it does only crash when rotating it, i mean wouldn't i have to crash when loading / drawing the image if the loadIMG function is the problem which it is since rotation does work when i load the image using img.LoadFromFile() :/
Any ideas how to fix the LoadIMG function?
Otherwise i'll just have to stuck with the unwrapped (still awesome
img.LoadFromFile() function.
Anyways thanks alot i'm really appreciating the community and your library of course
Looking forward to any replies,
greetings shmup.