Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blender: Protect embedded params #3763

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/windows/animated_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import os
import uuid

from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QPushButton
from PyQt5.QtWidgets import (
QApplication, QDialog, QDialogButtonBox, QPushButton
)

from classes import info, ui_util, metrics
from classes.app import get_app
Expand Down Expand Up @@ -64,7 +66,7 @@ def __init__(self):
# Hide render progress until needed
self.statusContainer.hide()

# Add blender treeview
# Add blender view
self.blenderView = BlenderListView(self)
self.verticalLayout.addWidget(self.blenderView)

Expand All @@ -86,11 +88,13 @@ def accept(self):
def closeEvent(self, event):
""" Actually close window and accept dialog """
self.blenderView.end_processing()
QApplication.restoreOverrideCursor()
super().accept()

def reject(self):
# Stop threads
self.blenderView.Cancel()
QApplication.restoreOverrideCursor()
super().reject()

def clear_effect_controls(self):
Expand Down
31 changes: 15 additions & 16 deletions src/windows/views/blender_listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from xml.dom import minidom as xml

from PyQt5.QtCore import (
Qt, QObject, pyqtSlot, pyqtSignal, QMetaObject, Q_ARG, QThread, QTimer, QSize,
Qt, QObject, pyqtSlot, pyqtSignal, QThread, QTimer, QSize,
)
from PyQt5.QtWidgets import (
QApplication, QListView, QMessageBox, QColorDialog,
Expand Down Expand Up @@ -207,7 +207,7 @@ def text_value_changed(self, widget, param, value=None):
except Exception:
log.debug('Failed to read plain text value from widget')
return
self.params[param["name"]] = value.replace("\n", "\\n")
self.params[param["name"]] = value
# XXX: This will log every individual KEYPRESS in the text field.
# log.info('Animation param %s set to %s' % (param["name"], value))

Expand Down Expand Up @@ -483,22 +483,19 @@ def onBlenderVersionError(self, version):
def onBlenderError(self, error=None):
self.error_with_blender(None, error)

def error_with_blender(self, version=None, command_output=None, log_text=None):
def error_with_blender(self, version=None, worker_message=None):
""" Show a friendly error message regarding the blender executable or version. """
_ = self.app._tr
s = settings.get_settings()

if log_text:
log.error("Blender output:\n%s", log_text)

error_message = ""
if version:
error_message = _("Version Detected: {}").format(version)
log.info("Blender version detected: {}".format(version))

if command_output:
error_message = _("Error Output:\n{}").format(command_output)
log.error("Blender error output:\n{}".format(command_output))
if worker_message:
error_message = _("Error Output:\n{}").format(worker_message)
log.error("Blender error: {}".format(worker_message))

msg = QMessageBox()
msg.setText(_("""
Expand All @@ -512,7 +509,6 @@ def error_with_blender(self, version=None, command_output=None, log_text=None):
{}""").format(info.BLENDER_MIN_VERSION,
s.get("blender_command"),
error_message))

msg.exec_()

# Enable the Render button again
Expand All @@ -533,7 +529,7 @@ def inject_params(self, source_path, out_path, frame=None):
param_data.update(self.get_project_params(is_preview))

param_serialization = json.dumps(param_data)
user_params += r'params_json = """{}"""'.format(
user_params += 'params_json = r' + '"""{}"""'.format(
param_serialization)

user_params += "\n#END INJECTING PARAMS\n"
Expand Down Expand Up @@ -631,7 +627,7 @@ def Render(self, frame=None):

# Cleanup signals all 'round
self.worker.finished.connect(self.worker.deleteLater)
self.worker.finished.connect(self.background.quit)
self.worker.finished.connect(self.background.quit, Qt.DirectConnection)
self.background.finished.connect(self.background.deleteLater)
self.background.finished.connect(self.worker.deleteLater)

Expand Down Expand Up @@ -745,7 +741,7 @@ def Cancel(self):
# Stop blender process if running
self.process.terminate()
self.canceled = True
self.closed.emit()
self.finished.emit()

def blender_version_check(self):
# Check the version of Blender
Expand Down Expand Up @@ -786,7 +782,7 @@ def blender_version_check(self):
ver_match = self.blender_version_re.search(ver_string)
if not ver_match:
raise Exception("No Blender version detected in output")
log.debug("Matched %s in output", str(ver_match))
log.debug("Matched %s in output", str(ver_match.group(0)))

self.version = ver_match.group(1)
log.info("Found Blender version {}".format(self.version))
Expand Down Expand Up @@ -880,10 +876,10 @@ def Render(self):
# Signal UI that background task is running
self.start_processing.emit()

except subprocess.SubprocessError:
except subprocess.SubprocessError as ex:
# Error running command. Most likely the blender executable path in
# the settings is incorrect, or is not a supported Blender version
self.blender_error_nodata.emit()
self.blender_error_with_data.emit(str(ex))
raise
except Exception:
log.error("Worker exception", exc_info=1)
Expand All @@ -900,6 +896,9 @@ def Render(self):
if self.canceled:
return
if self.frame_count < 1:
log.error("No frame detected from Blender!")
log.error("Blender output:\n{}".format(
self.command_output))
# Show Error that no frames are detected. This is likely caused by
# the wrong command being executed... or an error in Blender.
self.blender_error_with_data.emit(_("No frame was found in the output from Blender"))
Expand Down