Fix crash with loadables in Android. Warn if done() is being called twice.

This commit is contained in:
Alberto Torres 2024-08-29 00:13:37 +02:00
parent c731c3c5ab
commit e748831f3a
2 changed files with 15 additions and 11 deletions

View file

@ -281,9 +281,14 @@ proc loadUri*(
if not is_remote:
start_func = proc(self: LoadableResource) =
when not defined(release):
var done_called = false
try:
var memfile = memfiles.open(uri, mode=fmRead)
self.done_func = proc() =
when not defined(release):
assert not done_called, "Done is being called multiple times. Did you forget to set auto_done = false?"
done_called = true
memfile.close()
self.onload(true, "", memfile.mem, memfile.size)
# TODO!!!! check whether these objects are freed

View file

@ -88,14 +88,9 @@ proc registerBlendLoader*(engine: MyouEngine) =
e.newBlendLoader()
)
var used_resources: seq[LoadableResource]
method close*(self: BlendLoader) =
if self.resource != nil:
self.resource.done()
# TODO: investigate
# this is a hack to avoid a crasn on android
used_resources.add self.resource
self.resource = nil
self.blend_file = nil
self.cached_materials.clear()
@ -111,12 +106,16 @@ proc loadAsync(self: BlendLoader, callback: proc()) =
callback()
else:
self.close()
self.resource = self.blend_file_path.loadUri proc(ok, err, data, len: auto) =
self.resource = loadUri(self.blend_file_path,
proc(ok, err, data, len: auto) =
if ok:
self.blend_file = openBlendFile(self.blend_file_path, data, len)
callback()
else:
raise IOError.newException err
,
auto_done = false
)
type BlenderObTypes = enum
BEmpty = 0