开发者

Destructing in DSFML2

开发者 https://www.devze.com 2023-02-09 07:14 出处:网络
(Compiled with dmd v2.051) Code like this: import dsfml.graphics.all; void main() { while(true) auto rect = new Image(1024, 1024);

(Compiled with dmd v2.051)

Code like this:


import dsfml.graphics.all;

void main()
{   
    while(true)
        auto rect = new Image(1024, 1024);
}

Errors ou开发者_Go百科t in a minute, throwing an exception. I'd guess it's due to memory leaks.

Code like this, on the other hand, causes access violations and/or exceptions:

import dsfml.graphics.all;

void main()
{
    auto rect = new Image(1024, 1024);
    rect.dispose();
}

What am I actually supposed to do with Images, and other similar classes? I'd like to avoid both memory leaks and access violations.


Can't look at the code right now, but I think dispose() isn't really meant for public usage.

Remember that DSFML is just a wrapper around CSFML which in turn wraps SFML. You need to take a lot of care to ensure the user can't break anything. DSFML is fine for normal usage but can't handle extreme cases like your while(true) loop.

I've been thinking for a while if it would be better to switch to a SWIG-based approach to end this maintenance nightmare. This would probably also make it much easier to use extensions like SFGUI.

0

精彩评论

暂无评论...
验证码 换一张
取 消