Fix crash with loadables in Android. Warn if done()
is being called twice.
This commit is contained in:
parent
c731c3c5ab
commit
e748831f3a
|
@ -281,9 +281,14 @@ proc loadUri*(
|
||||||
|
|
||||||
if not is_remote:
|
if not is_remote:
|
||||||
start_func = proc(self: LoadableResource) =
|
start_func = proc(self: LoadableResource) =
|
||||||
|
when not defined(release):
|
||||||
|
var done_called = false
|
||||||
try:
|
try:
|
||||||
var memfile = memfiles.open(uri, mode=fmRead)
|
var memfile = memfiles.open(uri, mode=fmRead)
|
||||||
self.done_func = proc() =
|
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()
|
memfile.close()
|
||||||
self.onload(true, "", memfile.mem, memfile.size)
|
self.onload(true, "", memfile.mem, memfile.size)
|
||||||
# TODO!!!! check whether these objects are freed
|
# TODO!!!! check whether these objects are freed
|
||||||
|
|
|
@ -88,14 +88,9 @@ proc registerBlendLoader*(engine: MyouEngine) =
|
||||||
e.newBlendLoader()
|
e.newBlendLoader()
|
||||||
)
|
)
|
||||||
|
|
||||||
var used_resources: seq[LoadableResource]
|
|
||||||
|
|
||||||
method close*(self: BlendLoader) =
|
method close*(self: BlendLoader) =
|
||||||
if self.resource != nil:
|
if self.resource != nil:
|
||||||
self.resource.done()
|
self.resource.done()
|
||||||
# TODO: investigate
|
|
||||||
# this is a hack to avoid a crasn on android
|
|
||||||
used_resources.add self.resource
|
|
||||||
self.resource = nil
|
self.resource = nil
|
||||||
self.blend_file = nil
|
self.blend_file = nil
|
||||||
self.cached_materials.clear()
|
self.cached_materials.clear()
|
||||||
|
@ -111,12 +106,16 @@ proc loadAsync(self: BlendLoader, callback: proc()) =
|
||||||
callback()
|
callback()
|
||||||
else:
|
else:
|
||||||
self.close()
|
self.close()
|
||||||
self.resource = self.blend_file_path.loadUri proc(ok, err, data, len: auto) =
|
self.resource = loadUri(self.blend_file_path,
|
||||||
if ok:
|
proc(ok, err, data, len: auto) =
|
||||||
self.blend_file = openBlendFile(self.blend_file_path, data, len)
|
if ok:
|
||||||
callback()
|
self.blend_file = openBlendFile(self.blend_file_path, data, len)
|
||||||
else:
|
callback()
|
||||||
raise IOError.newException err
|
else:
|
||||||
|
raise IOError.newException err
|
||||||
|
,
|
||||||
|
auto_done = false
|
||||||
|
)
|
||||||
|
|
||||||
type BlenderObTypes = enum
|
type BlenderObTypes = enum
|
||||||
BEmpty = 0
|
BEmpty = 0
|
||||||
|
|
Loading…
Reference in a new issue