1
0
mirror of https://github.com/Escartem/AnimeWwise.git synced 2026-06-04 23:40:25 +08:00

fix memory leak

This commit is contained in:
Escartem
2024-07-26 22:42:38 +02:00
parent 2e1b3a7bb7
commit 85e7430f10
2 changed files with 23 additions and 14 deletions

View File

@@ -13,6 +13,9 @@ class Allocator:
self.files[filename] = mmap_object
def unload_file(self, name):
self.files[name].close()
def read_at(self, file, offset, size):
mmap_object = self.files[file]
mmap_object.seek(offset)

View File

@@ -226,7 +226,9 @@ class WwiseExtract:
print(": Extracting audio as wem")
all_sources = list(set([e["source"] for e in files]))
pos = 0
for source in all_sources:
# load source
load_path = path(_input, source)
if self.hdiff_dir is not None:
source = source.split(" (hdiff)")[0]
@@ -237,22 +239,26 @@ class WwiseExtract:
self.allocator.load_file(load_path)
pos = 0
for file in files:
pos += 1
self.update_progress(pos, len(files), 1)
# extract every file from this one
for file in [file for file in files if file["source"] == source]:
pos += 1
self.update_progress(pos, len(files), 1)
file["source"] = file["source"].split(" (hdiff)")[0]
data = self.allocator.read_at(file["source"], file["offset"], file["size"])
filepath = path("/".join(file["path"]), file["name"])
fullpath = path(output, filepath)
os.makedirs(os.path.dirname(fullpath), exist_ok=True)
with open(fullpath, "wb") as f:
f.write(data)
f.close()
file["source"] = file["source"].split(" (hdiff)")[0]
data = self.allocator.read_at(file["source"], file["offset"], file["size"])
filepath = path("/".join(file["path"]), file["name"])
fullpath = path(output, filepath)
os.makedirs(os.path.dirname(fullpath), exist_ok=True)
with open(fullpath, "wb") as f:
f.write(data)
f.close()
# unload source
self.allocator.unload_file(source)
# security
self.allocator.free_mem()
def extract_wav(self, _input, files, output):