Start a new topic

python: mgOpenDb and mgReadTexture memory problems

Original Post by: gmendieta Wed Apr 2 08:46:07 2014

Hi all!!

I have programmed an atlas generator that loads a couple of flts and generate some atlas of textures remapping automatically the models.

But i have some problems with the memory in python. Everytime i use mgOpenDb and mgReadTexture the memory raises, which is normal for me, but that memory is not free anytime.

i make mgInit(None, None) at the start of the whole program and mgExit at the end of it. I make something like

for each texture_region:

for each file:



# remapping code



and its done about 180 times with some testing and light files. So i dont know if there is some special code to free memory.

I guess mgReadTexture loads the texture in memory and dont deallocate it anytime.

Any idea????

p.d. Whenever the program is finished, ill show u a little video.

Original Post by: SteveThompson Wed Apr 2 15:17:21 2014

The OpenFlight API keeps a texture "cache" containing all the textures ever referenced by your program (even after you close a database). This is intended to make loading the texture the 2nd (and subsequent) time faster. The idea here is that you may load several databases, each referencing the same texture set and don't want to close and re-read the textures each time you close and open a new database.

Anyway, the memory "rise" is explained by this. You can clear the texture cache using the function mgPurgeTextures. Please read carefully the reference page for this function. In a standalone program or script, you can only call it when no databases are currently open. That said, in your case, you would call it after mgCloseDb.

Original Post by: gmendieta Wed Apr 2 15:24:27 2014

Hi Steve!!

Even its quite funny. I had write a little standalone python app that receive as parameter a flt path and a texture path and make

mgInit(None, None)

db = mgOpenDb(sys.argv[1])

is_free_entry, index = search_texture_palette_free_entry(db)

assert is_free_entry == True, "ERROR: no free entry in texture palette"

mgReadTexture(db, os.path.abspath(sys.argv[2]), index, 0, 0)

mgSaveAsDb(db, sys.argv[1])




hahahaha!! and call this little program as:

import subprocess

index ="python \"executable\" \"flt_path\" "texture_path"")

This way my main python interpreter doesnt use too many memory.

Thanks, i will test it right now.


Original Post by: SteveThompson Wed Apr 2 15:32:45 2014

Clever... thanks for sharing that Python tip. Other users may find this useful.


Login to post a comment