SFML community forums
Help => Graphics => Topic started by: Ankou on March 25, 2008, 11:04:53 pm
-
Hi
I have an sf::image created with new in the constructorcode of my object.
For testing purposes I have created an std::string with new at the same location.
When I'm deleting the sf::image in the destructor I get an access violation(I'm not using this object in any place I just created and deleted it)
It's not a problem with my class, because I can delete the string without problems.
So how can I delete the sf::Image without an access violation?(I have the same problem with an Smart Pointer(boost::shared_ptr) or when not using a pointer at all.
-
I have an sf::image created with new in the constructorcode of my object.
For testing purposes I have created an std::string with new at the same location.
You don't need these dynamic allocations at all.
Allocating a std::string with new is kind of horrible, as the main purpose of this class (and standard containers in general) is to hide the memory management ;)
I don't think there's something wrong with sf::Image destruction, you're the first one to report such issue, and I can't see what could crash in this class.
-
It was just for testing purposes first I had a Smart Pointer.
The std::string was just to test if it is only with sf::Image or with every object and yes, it seems only to happen with sf::Images(I also added another image to test if I do any stuff with it)
But yes it doesn't happen in general, in another testing class I could delete it without problems.
But sf::image is still the only case, so it has to do something with it, I just don't know what.
So I asked if anybody knows one possible reason for this behaviour...
It's late, I'm tired please excuse my horrible english...
-
Could you show us the code related to the destruction of your class ? Is it done at global program exit (is your object static / global ?) ?
-
yes that's it. I found and simplified the problem.
The following Code works:
class A
{
public:
sf::Image* test;
A() : test(NULL)
{
test = new sf::Image();
}
~A()
{
delete test;
test = NULL;
}
};
int main()
{
boost::shared_ptr<A> a = boost::shared_ptr<A>(new A());
}
This following does not!:
class A
{
public:
sf::Image* test;
A() : test(NULL)
{
test = new sf::Image();
}
~A()
{
delete test;
test = NULL;
}
};
boost::shared_ptr<A> a;
int main()
{
a = boost::shared_ptr<A>(new A());
}
But it shouldn't be a problem because I only use global variables for testing so I have just to remove the test and implement the real code and it should work
-
It shouldn't crash however, as images are supposed to be aware of the destruction of the OpenGL context.
Is there any error message on the standard output ?
-
sorry that it took so long to answer:
no, there's no Output.
Don't you have the same problem, when you run my Code?(I'm using Visual C++ 2008)
-
No, sorry. I'll try to test it as soon as posible.