How to toggle Fullscreen/Windowed

BlitzMax Forums/BlitzMax Programming/How to toggle Fullscreen/Windowed

HrdNutz(Posted 2005) [#1]
Hey all,

Any one know how to do this properly? If I just do EndGraphics and then Graphics(...) it works, but memory usage increases drastically. Is ther a better way of doing this?

Thanks in advance,
Dima


HrdNutz(Posted 2005) [#2]
Anyone do this successfully yet? Seems like a simple task, but for some reason I am not smart enough to figure it out.


deps(Posted 2005) [#3]
I wrote this little test and the mem usage sure is increasing:

However, The memory is not really used, it just hangs around for a while in case the game needs to allocate more memory. When that happends the unused memory is going to be recycled. So I don't think you should worry about it.


HrdNutz(Posted 2005) [#4]
The problem is much bigger when I have graphics loaded. I also tried this game C'Bubble, which was developed in bmax, they have hte same problem. If you open task manager, and watch memory usage for the app, every time the graphics mode is changed it gains about 4-5MB, so after 5 times, a 10MB file becomes 35-40MB and it doesn't seem to free it up at all.

There must be a way to deal with this ...

Thanks for the help.


TartanTangerine (was Indiepath)(Posted 2005) [#5]
I don't have the same problem here and I did not have it when I was testing cbubble.


HrdNutz(Posted 2005) [#6]
Very strange, I gain about 9MB every time I switch to full screen and back in c'bubble. Happens with my own app as well, but less, probably because I have less gfx.


JazzieB(Posted 2005) [#7]
Although I've yet to implement this sort of thing in BlitzMax, I did notice it in my Blitz3D games where I allowed the user to set their display preferences.

Anyway, then I let the increase go because once a user has selected their preferred windowed or full-screen mode, which they will only do once most of the time, they will not change it again - especially during the same session. When they next come to run the game, they won't change it - unless they upgrade their graphics card or something, so everything will be fine.

Having said that, I've seen a similar increase in my BlitzMax games on Windows when I allow the player to select which graphics drivers they want to use (OpenGL or DirectX). I basically Null all the image handles, call FlushMem/GCCollect, call EndGraphics and then switch modes and reload the media. Again, I've not worried about the increase because either a player won't bother changing it in this case (only one display size supported) or they will only change it once.

Apart from all that, it would be nice to know what we should be doing in these graphics mode changes, as I'm sure that some people would like to use different display settings for different parts of their programs. Myself for one, would like to switch to a set resolution for the level editor and the user-defined resolution while playing the game (ok, not quite the same as full/windowed mode, but related nonetheless).


FlameDuck(Posted 2005) [#8]
There must be a way to deal with this ...
What is it exactly you want to "deal" with? This code is adapted from deps' code above:
Strict
'SetGraphicsDriver GLMax2DDriver()
Print "memory usage: " + GCMemAlloced()
For Local i = 0 To 25
Print i
Graphics 640,480,0
Print "memory usage: " + GCMemAlloced()
EndGraphics()

Graphics 800,640,0
Print "memory usage: " + GCMemAlloced()
EndGraphics()

Graphics 1024,768,0
Print "memory usage: " + GCMemAlloced()
EndGraphics()

Graphics 320,240,0
Print "memory usage: " + GCMemAlloced()
EndGraphics()

Print "memory usage: " + GCMemAlloced()
Next
As you can see, memory will be reclaimed when nessecary.


HrdNutz(Posted 2005) [#9]
I do call EndGraphics before calling Graphisc() again, but every time, my apps gains about 4-5 megs in size. Don't know when will BMAX consider it 'necessary' to reclaim it, but it would be nice if it did, or if I could do it manually.

Am I supposed to unload all the graphics before I switch to full screen and versa? The code that you guys posted here gains very minimal amount of memory, but running my small game, or c'bubble gets MUCH bigger mem usage with every switch. Maybe the graphics NEED to be released and reloaded? that would be very unwanted ...


HrdNutz(Posted 2005) [#10]
Please try C'Bubble and see if you get the same problem I am getting. A few switches between fullscreen and window and the app gets much bigger in the task manager. I tried this just now on my laptop and the same results.


TartanTangerine (was Indiepath)(Posted 2005) [#11]
Try it, I wrote it. I don't have your problems (oooerr), my memory gets freeeeeeeeed.

I don't reload the GFX after a change so I really do not know what the issue is.

PS. When you gonna buy it eh?


HrdNutz(Posted 2005) [#12]
I would have thouhgt that this might be a problem with my system, but not. My laptop has identical issues. I would post screenshots, but don't have a place.

In short words; C'Bubble takes 100 MB of memory after startup. After doing 10 consecutive mode changes, app becomes 150 MB. That's 50 megs more than it started with. Have you tried doing that many mode switches? I cannot believe that you aren't seeing this problem, and I get it on both my systems.


REDi(Posted 2005) [#13]
Just tried C'Bubble, very nice game well done Indie, but when I switched to windowed mode, it started leaking about 600K per refresh in task manager.

C'Bubble takes 100 MB of memory after startup

It was more like 4MB on my machine.


HrdNutz(Posted 2005) [#14]
Ah, try starting it in windowed mode. In full screen, i see about 4 megs used, after switching to windowed, it becomes 25megs. If I start the game, and it's already in windowed mode, it takes about 107MB.


REDi(Posted 2005) [#15]
Yeah weird, I started it in fullscreen and it was around 100MB, but it didn't leak that time. And HrdNutz is correct, everytime I switch screen mode the memory usage goes up ~10MB.


HrdNutz(Posted 2005) [#16]
At least I feel better now that someone else is having the same problem, so I know now it's not me, but possibly a bug in bmax or there is something special that needs to be done in order to keep everything proper.

Anyone else have any thoughts or ideas? I am also wondering if I should even bother worrying about this, but it seems like something not to ignore completely.

IndiePath, I am still shocked that you are not seeing this happening with C'Bubble.


Grisu(Posted 2005) [#17]
And another bug for me.
If you click the close window button in window mode your app will still run in memory (check taskmanager)! BMX1.14.

Any fix for this?