Jaded-Encoding-Thaumaturgy / vs-preview

Previewer for VapourSynth scripts.
Apache License 2.0
61 stars 19 forks source link

when loading a new script that errors on first load vspreview crashes on reload #128

Closed jsaowji closed 5 months ago

jsaowji commented 7 months ago

Really annoying you write a script, open it in vspreview, you misstyped lwlibavsource, vspreview crashes and you need to restart.

# repro script
import sys
if "asd" not in sys.modules:
    sys.modules['asd'] =  object()

    assert False
else:
    del sys.modules["asd"]
    from vstools import core
    core.std.BlankClip().set_output(0)
Traceback (most recent call last):
  File "/home/user/git/vs-preview/vspreview/main/timeline.py", line 99, in paintEvent
    self.drawWidget(QPainter(self))
  File "/home/user/git/vs-preview/vspreview/main/timeline.py", line 102, in drawWidget
    setup_key = (self.rect_f, self.main.current_output.index)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'index'
QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
QPaintDevice: Cannot destroy paint device that is being painted
Traceback (most recent call last):
  File "/home/user/git/vs-preview/vspreview/main/timeline.py", line 99, in paintEvent
    self.drawWidget(QPainter(self))
  File "/home/user/git/vs-preview/vspreview/main/timeline.py", line 102, in drawWidget
    setup_key = (self.rect_f, self.main.current_output.index)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'index'
QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
QPaintDevice: Cannot destroy paint device that is being painted
zsh: segmentation fault  python -m vspreview repro.py

maybe this is a clean fix enough dunno

diff --git a/vspreview/main/window.py b/vspreview/main/window.py
index 39f13de..6c16095 100644
--- a/vspreview/main/window.py
+++ b/vspreview/main/window.py
@@ -399,7 +399,7 @@ class MainWindow(AbstractQItem, QMainWindow, QAbstractYAMLObjectSingleton):
             if self.storage_not_found or reload_from_error:
                 self.load_storage()

-            if not reloading:
+            if not reloading or (self.outputs is None):
                 self.toolbars.main.rescan_outputs()
                 self.toolbars.playback.rescan_outputs()
Setsugennoao commented 5 months ago

Since you found the fix, can you make a PR?