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 / Loading too many images

Author
Message
Brian Lancaster
4
Years of Service
User Offline
Joined: 20th Dec 2013
Location:
Posted: 22nd Nov 2015 05:51
Hello all,
I have one final bug to work out. When I load over about 600 images at one time the game will crash and say that the next image does not exist. I've tried it on many computers and it's always around the same number of loaded images.
This isn't too big of a problem, because to get that many images, the player will have to visit over 12 maps in one play session without closing the program. The maps are huge and this will probably never happen, but just in case a player decides to play all night and visit over 12 maps without restarting the program, is there any way to fix this?
I have no idea how memblocks work, would they help? Thanks.
Brian
Is it not dust which from a thousand shelves
Imprisons me behind this towering wall
(of porn)?
wattywatts
9
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 22nd Nov 2015 15:19
I must not be understanding the problem; what's wrong with deleting the images that aren't currently being used?
Brian Lancaster
4
Years of Service
User Offline
Joined: 20th Dec 2013
Location:
Posted: 23rd Nov 2015 10:19
Oh ya, I tried deleting images when going to a new map and resetting the display mode, but the problem remains. It seems even after deleting the images the memory is still taken up. I'm not even sure it's a memory problem because it just says it can't find the next image, but I'm guessing it's a memory problem.
Has anyone had a similar experience?
Is it not dust which from a thousand shelves
Imprisons me behind this towering wall
(of porn)?
zoltar
7
Years of Service
User Offline
Joined: 2nd Mar 2011
Location:
Posted: 25th Nov 2015 19:20 Edited at: 25th Nov 2015 19:20
@Brian Lancaster: Hi, Brian. It's hard to tell what's going on without having the actual code. I'll try to cover, however, a few points that might help you to figure out the problem and its solution.

1. There's a limit in the number of images you can create index-wise but 600 is nowhere near to it. From the documentation, this limit is 65,535.
2. Don't take for granted the existence of an image. Use the IMAGE EXIST command before you use an image. Image indexes must be in the range [1, 65 535], otherwise the command produces a run-time error.
3. I vaguely remember Lee saying that with DirectX 9 (DarkBASIC uses it) you have about 1.5 GB of memory to work. Keep in mind that the space used by an image on disk might differ from the space it uses in memory. Use the Windows Task Manager to roughly find out how much memory is using your game.
4. Create sprites from images and use those instead of having the images directly drawn on screen. You can create several sprites from a single image and draw a single sprite on screen several times using the PASTE SPRITE command.
5. Divide and conquer. Unless all the maps in the game use the whole lot of images, there's no need to have them loaded into memory at the same time. In a very simplistic way, each time a player reach a map load the required images for that map and when that map is finished delete all the images. The same goes for sprites and other resources.
Morcilla
15
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 30th Nov 2015 15:47
Hi,

Please test this code to see how many images can be loaded:



It creates an image, saves it to disk, and try to load it as many times as it can. Add ",1" at the end of the "load image" command, to turn off mipmapping.

My numbers:

171 512x512 images loaded with mipmapping
1682 512x512 images loaded withOUT mipmapping

So, as you can see, the amount of images that can be loaded depends on mipmapping parameter during the load.

Also, it seems that somehow .dds image files 'fit' and accommodate much better into memory than other file formats like .jpg, so bear this in mind too, as it could increase dramatically the number of images that can be loaded, as well as the overall stability of your running program. Eating up the memory uses to randomly exit the program with unexpected/unpredictable errors arising.

Regarding this, loading and deleting .jpg files repeatedly result in less and less images fitting into memory, it seems some sort of memory leaking or memory just not being completely released.
However performing the same operation with .dds files seems to work endlessly well.

Hope that helps.



Login to post a reply

Server time is: 2018-10-15 15:57:24
Your offset time is: 2018-10-15 15:57:24