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.
p.d. Whenever the program is finished, ill show u a little video.
Clever... thanks for sharing that Python tip. Other users may find this useful.
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
db = mgOpenDb(sys.argv)
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), index, 0, 0)
hahahaha!! and call this little program as:
index = subprocess.call("python \"executable\" \"flt_path\" "texture_path"")
This way my main python interpreter doesnt use too many memory.
Thanks, i will test it right now.
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.