Change new_scenes to new_del_scenes to avoid issues when deleting a scene.

This commit is contained in:
Alberto Torres 2024-11-30 00:53:01 +01:00
parent 2caf78c88a
commit bb4f8e1c00
4 changed files with 12 additions and 10 deletions

View file

@ -628,7 +628,7 @@ method loadScene*(self: BlendLoader, name: string="", scene: Scene=nil, callback
callback(getCurrentExceptionMsg(), nil)
return
callback("", scene)
if scene.name notin self.engine.new_scenes:
if self.engine.new_del_scenes.getOrDefault(scene.name).isNil:
# it was deleted
return
# TODO: when loading is async, move this stuff after loading has

View file

@ -173,11 +173,14 @@ proc myou_main_loop*(self: MyouEngine) =
updateLoadableWorkerThreads()
# TODO: make a table object that can be iterated while changing, e.g. with a
# seq and a dirty flag to update the seq
if self.new_scenes.len != 0:
for name,scene in self.new_scenes.pairs:
self.scenes[name] = scene
self.new_scenes.clear()
let time = getmonotime().ticks.float/1000000000
if self.new_del_scenes.len != 0:
for name,scene in self.new_del_scenes.pairs:
if scene.nonNil:
self.scenes[name] = scene
else: # nil means that the scene is meant to be deleted
self.scenes.del(name)
self.new_del_scenes.clear()
let time = getmonotime().ticks.float/1_000_000_000
let delta_seconds = time - last_time
for _,scene in self.scenes.pairs:
if not scene.enabled:

View file

@ -96,7 +96,7 @@ proc initScene*(self: Scene, engine: MyouEngine, name: string = "Scene",
while self.name in engine.scenes:
collision_seq += 1
self.name = name & "$" & $collision_seq
engine.new_scenes[self.name] = self
engine.new_del_scenes[self.name] = self
self.mesh_passes.setLen 3
self.world = newWorld(self)
self.background_color = vec4(0, 0, 0, 1)
@ -379,8 +379,7 @@ proc destroy*(self: Scene) =
for cube in self.cubemaps:
cube.destroy()
self.cubemaps = @[]
self.engine.scenes.del(self.name)
self.engine.new_scenes.del(self.name)
self.engine.new_del_scenes[self.name] = nil
# bound textures can linger
unbindAllTextures()
# probably none of this is actually necessary

View file

@ -86,7 +86,7 @@ type
glsl_version*: string
cache_settings*: CacheSettings
all_framebuffers*: seq[Framebuffer] ## private
new_scenes*: Table[string, Scene] ## private
new_del_scenes*: Table[string, Scene] ## private
# gameobject.nim