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

Author
Message
Brian Lancaster
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Oakland, CA
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)?

The author of this post has marked a post as an answer.

Go to answer

wattywatts
14
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
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Oakland, CA
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
13
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
21
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.



Brian Lancaster
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Oakland, CA
Posted: 7th Sep 2019 01:17
This post has been marked by the post author as the answer.
Damn, I missed these answers. The DDS files I think really fixed the problem. I was using PNGs. When I first started it was JPGs and it took 3 minutes to load each level, wasted so much time back then.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 8th Oct 2019 22:16
Your issue is undoubtedly that you are maxing out on available RAM. Since DBPro can only create 32bit apps, you are capped in and around 2-3GB of memory.
You need to create a system to properly manage your loaded images. So you don't load duplicate images, and delete un-needed images.
You might also create a system to designate images that are not cleared from memory, to prevent long load situations. One more thing is you should be wrapping most of the DBP commands with wrapper functions to handle preventable errors like missing files.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!

Login to post a reply

Server time is: 2024-03-28 16:38:20
Your offset time is: 2024-03-28 16:38:20