Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Display Mode change...memory leak?

Author
Message
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 23rd Oct 2011 15:10
Hi, Does anyone know if theres a memory leak caused by changing the display mode? I've created a program that seems to like to eat memory when the res is changed. It changes the resolution when the window is resized, but it tends to eat a bit more memory each time. It doesn't actually use much in the way of media, as most of it is drawn using the D3D plugin. I've created a little function to clear as much resources as I can, before the display mode is changed, which helped a little bit. The only thing I can't seem to clear are the D3D fonts which seem to take up more memory when used and reloaded each time.

Nick

IlluminatedFX.com
For web design and graphic design services
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Oct 2011 15:32
I don't think you are supposed to change the display mode during runtime. Why would you anyway?

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 23rd Oct 2011 15:50
Quote: "I don't think you are supposed to change the display mode during runtime."

Well why would there be a "set display mode" command then...

Quote: "Why would you anyway?"

Read his post, it's for when the window is resized.

@NickH
Try making a simple program which just changes the display mode as fast as it can and see if it eats up all your memory. If it does then I suggest posting in the bug reports forum with the code which demonstrates it.

[b]
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 23rd Oct 2011 20:34
Thanks DIggsey I had a test version of the window resizing part of the program and yes it does slowly eat mroe memory, though not as much as my full program


IlluminatedFX.com
For web design and graphic design services
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 23rd Oct 2011 21:49 Edited at: 23rd Oct 2011 21:55
The SetDisplayMode command will flush your object, sprite and video memory data. Perhaps this is what is slowing things down; otherwise I'm not sure what is going on; you should time each function call to see where the major bottle neck is.

If the issue persists, have a play around with Render Targets. Basically Render Targets allow you to draw a camera result to an image, which can be resized, or clipped off the window, with the constraint of perhaps, the screen size. Hopefully, resizing the render target is lighter work for the engine, than changing the display mode.

I've not written a tutorial on render targets but the here is an explanation.

You create a camera, and use [set camera to image], of the size of your window. What you do with the image is up to you, EG: sprite it, paste it or bitmap copy it.

The negative equivilent of your camera Id will give you the Id for the bitmap it is rendering to. So camera 1, uses bitmap -1, camera two uses bitmap -2, camera 0 is obviously 0. Set bitmap format can also help you control what pixel data the cameras will draw.

Consider using Sync Mask to only render the extra camera when something has changed, do not Sync the display if nothing visible has changed.

EDIT

Set Camera View, is another solution; but I think it will not change the proportions

NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 24th Oct 2011 12:39 Edited at: 24th Oct 2011 12:48
@Chris. It's not really the speed which is an issue, it's memory useage as a result of the display mode being changed and the fact it seems like not everything is flushed.

I've used render targets in my current program, though only for generating the typical chequor background you see in graphics software. Thanks

IlluminatedFX.com
For web design and graphic design services
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 13:07
I've found render targets might not be flushed properly in a simple image cropping / joining utility I made for someone. It works fine for me but not for them. Could that be the cause?

NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 24th Oct 2011 14:07 Edited at: 24th Oct 2011 14:08
Could be I suppose, it's difficult to say. If I could delete the D3D fonts I'd save a few mb. I've even gone as far as undiming arrays, deleting images and sprites before the res change. I think that helped slightly, but not much. It's odd though as I don't actually use much media anyway and the only media that is of any potential size is the image the user loads. I've seen my little program using over 170mb of RAM which is a little OTT!

IlluminatedFX.com
For web design and graphic design services
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2011 14:12
Have you tried diggsey's advanced 2D plugin for the fonts? Maybe they clear properly?

'Maybe' is not meant in an offensive way BTW Diggsey

NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 24th Oct 2011 16:14 Edited at: 24th Oct 2011 19:47
I had thought about that, but thats quite a bit of work! My GUI system has about 1000 lines of code for a lot of different gadgets. Though I'm not using many of them here, and some are remarked out, but still... I might eventually.

PS That may be the most diplomatic anyone has ever been on this forum!

IlluminatedFX.com
For web design and graphic design services

Login to post a reply

Server time is: 2026-07-11 14:37:49
Your offset time is: 2026-07-11 14:37:49