Ok i am trying to wrap some classes in d with the csfml derelict bindings and naturally i want to destroy the sfml object with destructor however when i do that it crashes.
If i where to remove the destructor and have a manual destruction method to the class it doesnt crash if i where not to have a destructor or a destroy method and just leave the memory around it still works but the moment i use the destroy in a destructor it crashes.
It crashes with this error as reported by mago debugger:
First-chance exception: core.exception.InvalidMemoryOperationError
I dont understand why this happens inside a destructor but not in a method that does the same thing. Here is my test code about as minimal as i can make it to demonstrate:
module main;
import derelict.sfml2.system;
import derelict.sfml2.window;
import derelict.sfml2.graphics;
pragma(lib, "derelictUtil.lib");
pragma(lib, "derelictSFML2.lib");
class Image {
sfImage* image;
this(uint width, uint height) {
image = sfImage_create(width, height);
}
~this() {
this.destroy();
}
void destroy() {
sfImage_destroy(image);
}
}
void main() {
DerelictSFML2System.load();
DerelictSFML2Window.load();
DerelictSFML2Graphics.load();
auto image = sfImage_create(100, 100);
sfImage_destroy(image);
auto myimage = new Image(100, 100);
//myimage.destroy();
}
Can anyone tell my why this is happening and or how to fix it?