BrokenSource / DepthFlow

🌊 Image to → 2.5D Parallax Effect Video. High quality, user first. Free and Open Source Leiapix alternative
https://brokensrc.dev
GNU Affero General Public License v3.0
153 stars 11 forks source link

(BUG) 'NoneType' object has no attribute 'get' #22

Closed steve02081504 closed 1 month ago

steve02081504 commented 1 month ago
 >depthflow input -i C:\Users\steve02081504\Downloads\116018494_p0.png main
│DepthFlow ├┤ 732ms├┤INFO   │ ▸ ( 1) DepthFlowScene     │ ▸ Module added to the Scene
│DepthFlow ├┤ 736ms├┤INFO   │ ▸ ( 1) DepthFlowScene     │ ▸ Creating glfw Window
│DepthFlow ├┤ 834ms├┤INFO   │ ▸ ( 1) DepthFlowScene     │ ▸ Adding default base Scene
modules
│DepthFlow ├┤ 835ms├┤INFO   │ ▸ ( 2) ShaderFrametimer   │ ▸ Module added to the Scene
│DepthFlow ├┤ 836ms├┤INFO   │ ▸ ( 3) ShaderKeyboard     │ ▸ Module added to the Scene
│DepthFlow ├┤ 837ms├┤INFO   │ ▸ ( 4) ShaderCamera       │ ▸ Module added to the Scene
│DepthFlow ├┤ 838ms├┤INFO   │ ▸ ( 5) ShaderDynamics     │ ▸ Module added to the Scene
│DepthFlow ├┤ 839ms├┤INFO   │ ▸ ( 6) ShaderDynamics     │ ▸ Module added to the Scene
│DepthFlow ├┤ 840ms├┤INFO   │ ▸ ( 7) ShaderDynamics     │ ▸ Module added to the Scene
│DepthFlow ├┤ 841ms├┤INFO   │ ▸ ( 8) ShaderDynamics     │ ▸ Module added to the Scene
│DepthFlow ├┤ 842ms├┤INFO   │ ▸ ( 9) ShaderDynamics     │ ▸ Module added to the Scene
│DepthFlow ├┤ 842ms├┤INFO   │ ▸ (10) ShaderDynamics     │ ▸ Module added to the Scene
│DepthFlow ├┤ 843ms├┤INFO   │ ▸ (11) ShaderDynamics     │ ▸ Module added to the Scene
│DepthFlow ├┤ 844ms├┤INFO   │ ▸ (12) ShaderDynamics     │ ▸ Module added to the Scene
│DepthFlow ├┤ 845ms├┤INFO   │ ▸ ( 1) DepthFlowScene     │ ▸ Creating SSAA
Implementation
│DepthFlow ├┤ 846ms├┤INFO   │ ▸ (13) ShaderObject       │ ▸ Module added to the Scene
│DepthFlow ├┤ 847ms├┤INFO   │ ▸ (14) ShaderTexture      │ ▸ Module added to the Scene
│DepthFlow ├┤ 851ms├┤INFO   │ ▸ (15) ShaderObject       │ ▸ Module added to the Scene
│DepthFlow ├┤ 852ms├┤INFO   │ ▸ (16) ShaderTexture      │ ▸ Module added to the Scene
│DepthFlow ├┤ 858ms├┤INFO   │ ▸ (17) ShaderTexture      │ ▸ Module added to the Scene
│DepthFlow ├┤ 860ms├┤INFO   │ ▸ (18) ShaderTexture      │ ▸ Module added to the Scene
│DepthFlow ├┤1248ms├┤SUCCESS│ ▸ DepthMap already cached on
(C:\Users\steve02081504\AppData\Local\BrokenSource\DepthFlow\Cache\b18ab620-3e48-6a72-4
a3f-b0b8d309b216.depth.png)
│DepthFlow ├┤1286ms├┤SUCCESS│ ▸ Already upscaled to target size (0, 0):
<PIL.Image.Image image mode=L size=518x518 at 0x1FC6D6B18B0>
│DepthFlow ├┤1287ms├┤SUCCESS│ ▸ Already upscaled to target size (0, 0):
<PIL.PngImagePlugin.PngImageFile image mode=RGB size=2048x2048 at 0x1FC5157F260>

---------------------------------------------------------------------------------------
198 _run_module_as_main <frozen runpy>
>

88 _run_code <frozen runpy>
>

7 <module> E:\Python\Scripts\depthflow.exe\__main__.py
> sys.exit(main())

10 main E:\Python\Lib\site-packages\DepthFlow\__main__.py
> depthflow.cli(sys.argv[1:])

574 cli E:\Python\Lib\site-packages\ShaderFlow\Scene.py
> self.broken_typer(args)

111 __call__ E:\Python\Lib\site-packages\Broken\Core\BrokenTyper.py
> raise error

105 __call__ E:\Python\Lib\site-packages\Broken\Core\BrokenTyper.py
> self.app(args)

326 __call__ E:\Python\Lib\site-packages\typer\main.py
> raise e

309 __call__ E:\Python\Lib\site-packages\typer\main.py
> return get_command(self)(*args, **kwargs)

1157 __call__ E:\Python\Lib\site-packages\click\core.py
> return self.main(*args, **kwargs)

723 main E:\Python\Lib\site-packages\typer\core.py
> return _main(

193 _main E:\Python\Lib\site-packages\typer\core.py
> rv = self.invoke(ctx)

1719 invoke E:\Python\Lib\site-packages\click\core.py
> rv.append(sub_ctx.command.invoke(sub_ctx))

1434 invoke E:\Python\Lib\site-packages\click\core.py
> return ctx.invoke(self.callback, **ctx.params)

783 invoke E:\Python\Lib\site-packages\click\core.py
> return __callback(*args, **kwargs)

692 wrapper E:\Python\Lib\site-packages\typer\main.py
> return callback(**use_params)

722 main E:\Python\Lib\site-packages\ShaderFlow\Scene.py
> video_resolution = self.resize(width=width, height=height, scale=scale, aspect_ratio=aspect)

477 resize E:\Python\Lib\site-packages\ShaderFlow\Scene.py
> self.window.size = self.resolution

145 size E:\Python\Lib\site-packages\moderngl_window\context\glfw\window.py
> glfw.set_window_size(self._window, value[0], value[1])

1382 set_window_size E:\Python\Lib\site-packages\glfw\__init__.py
> _glfw.glfwSetWindowSize(window, width, height)

689 errcheck E:\Python\Lib\site-packages\glfw\__init__.py
> _reraise(exc[1], exc[2])

70 _reraise E:\Python\Lib\site-packages\glfw\__init__.py
> raise exception.with_traceback(traceback)

668 callback_wrapper E:\Python\Lib\site-packages\glfw\__init__.py
> return func(*args, **kwargs)

374 glfw_window_resize_callback ...site-packages\moderngl_window\context\glfw\window.py> super().resize(self._buffer_width, self._buffer_height)

756 resize E:\Python\Lib\site-packages\moderngl_window\context\base\window.py
> self._resize_func(width, height)

942 __window_resize__ E:\Python\Lib\site-packages\ShaderFlow\Scene.py
> self.relay(Message.Shader.Render)

42 relay E:\Python\Lib\site-packages\ShaderFlow\Module.py
> module.handle(message)

379 handle E:\Python\Lib\site-packages\ShaderFlow\Shader.py
> self.render()

366 render E:\Python\Lib\site-packages\ShaderFlow\Shader.py
> self.use_pipeline(self._full_pipeline())

356 use_pipeline E:\Python\Lib\site-packages\ShaderFlow\Shader.py
> self.set_uniform(variable.name, variable.value)

276 set_uniform E:\Python\Lib\site-packages\ShaderFlow\Shader.py

  @fragment.setter
  def fragment(self, value: Union[Path, str]):
      self._watchshader(value)
      self._fragment = value

  # # Uniforms

  def set_uniform(self, name: str, value: Any=None) -> None:
      # Note: Denum safety, called hundreds of times: No noticeable performance impact (?)
>     if (value is not None) and (uniform := self.program.get(name, None)):
          uniform.value = denum(value)

  def get_uniform(self, name: str) -> Any | None:
      return self.program.get(name, None)

  # # Rendering

  def _full_pipeline(self) -> Iterable[ShaderVariable]:
      for module in self.scene.modules:
          yield from module.pipeline()

AttributeError:
'NoneType' object has no attribute 'get'
Tremeschin commented 1 month ago

I think I know what happened here, it seems like an Windows+GLFW different behavior than what I expected

Long story short, this line calls an immediate render when any window resize happens, as it might happen before finishing a scene with multiple shaders (and give visual artifacts). The GLFW window is started as hidden, but when deciding the final render resolution it sends a resize signal on Windows when hidden, but not Linux where I develop, and tries to render the shaders before they are compiled (self.program == None)

I've pushed a commit 8af4de6 that inverts this order, but didn't try yet on Windows

Can you run pip install --upgrade git+https://github.com/BrokenSource/ShaderFlow.git to use this latest version temporarily, to see if it fixes it?

To revert, pip uninstall shaderflow and again pip install --force-reinstall broken-source

I will push a wheel soon™ with some other docker fix as well so you can have a working 0.3.2 version

steve02081504 commented 1 month ago

Your fix does work! Another problem is that after I updated and ran it, I found it difficult to resize the window: the aspect ratio seems to be fixed and beyond the screen

Tremeschin commented 1 month ago

Your fix does work!

Great! 👍🏻

I found it difficult to resize the window: the aspect ratio seems to be fixed and beyond the screen

The aspect ratio is indeed fixed to the input image's one, so that no out of bounds edges are rendered on realtime or when exporting to a video. I just noticed there's no easy way to revert it to "dynamic" on the CLI (probably what you're expecting how a window should resize), will think of an way to signal this on the main function

I'm not limiting real time resizes to the monitor size at the moment, due some recursions errors I couldn't fix (ie. bad logic) at the time, but I can revisit this soon-ish. Though it is limited when you send -w -h to the main command

One last thing, I know that on Windows the GUI freezes when resized, here's the related GLFW issue if you found it annoying, not much we can do at the moment, other window backends didn't work as well as GLFW on my testings