mirror of
https://github.com/Escartem/AnimeWwise.git
synced 2026-06-19 01:40:23 +08:00
fix memory leak
This commit is contained in:
@@ -13,6 +13,9 @@ class Allocator:
|
|||||||
|
|
||||||
self.files[filename] = mmap_object
|
self.files[filename] = mmap_object
|
||||||
|
|
||||||
|
def unload_file(self, name):
|
||||||
|
self.files[name].close()
|
||||||
|
|
||||||
def read_at(self, file, offset, size):
|
def read_at(self, file, offset, size):
|
||||||
mmap_object = self.files[file]
|
mmap_object = self.files[file]
|
||||||
mmap_object.seek(offset)
|
mmap_object.seek(offset)
|
||||||
|
|||||||
34
extract.py
34
extract.py
@@ -226,7 +226,9 @@ class WwiseExtract:
|
|||||||
print(": Extracting audio as wem")
|
print(": Extracting audio as wem")
|
||||||
all_sources = list(set([e["source"] for e in files]))
|
all_sources = list(set([e["source"] for e in files]))
|
||||||
|
|
||||||
|
pos = 0
|
||||||
for source in all_sources:
|
for source in all_sources:
|
||||||
|
# load source
|
||||||
load_path = path(_input, source)
|
load_path = path(_input, source)
|
||||||
if self.hdiff_dir is not None:
|
if self.hdiff_dir is not None:
|
||||||
source = source.split(" (hdiff)")[0]
|
source = source.split(" (hdiff)")[0]
|
||||||
@@ -237,22 +239,26 @@ class WwiseExtract:
|
|||||||
|
|
||||||
self.allocator.load_file(load_path)
|
self.allocator.load_file(load_path)
|
||||||
|
|
||||||
pos = 0
|
# extract every file from this one
|
||||||
for file in files:
|
for file in [file for file in files if file["source"] == source]:
|
||||||
pos += 1
|
pos += 1
|
||||||
self.update_progress(pos, len(files), 1)
|
self.update_progress(pos, len(files), 1)
|
||||||
|
|
||||||
file["source"] = file["source"].split(" (hdiff)")[0]
|
file["source"] = file["source"].split(" (hdiff)")[0]
|
||||||
data = self.allocator.read_at(file["source"], file["offset"], file["size"])
|
data = self.allocator.read_at(file["source"], file["offset"], file["size"])
|
||||||
|
|
||||||
filepath = path("/".join(file["path"]), file["name"])
|
filepath = path("/".join(file["path"]), file["name"])
|
||||||
fullpath = path(output, filepath)
|
fullpath = path(output, filepath)
|
||||||
os.makedirs(os.path.dirname(fullpath), exist_ok=True)
|
os.makedirs(os.path.dirname(fullpath), exist_ok=True)
|
||||||
|
|
||||||
with open(fullpath, "wb") as f:
|
with open(fullpath, "wb") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# unload source
|
||||||
|
self.allocator.unload_file(source)
|
||||||
|
|
||||||
|
# security
|
||||||
self.allocator.free_mem()
|
self.allocator.free_mem()
|
||||||
|
|
||||||
def extract_wav(self, _input, files, output):
|
def extract_wav(self, _input, files, output):
|
||||||
|
|||||||
Reference in New Issue
Block a user