Skip to content

Commit

Permalink
Fixed freezing when using Krita 5.2.5 / 5.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuntokon committed Oct 22, 2024
1 parent a7f9cc4 commit 6df69d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
12 changes: 8 additions & 4 deletions blender_layer/blenderLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ def startStopServer(self):
self.server.signals.connected.connect(self.onServerConnected)
self.server.signals.error.connect(self.setStatus)
self.server.signals.msgReceived.connect(self.handleMessage)
self.server.signals.refresh.connect(self.refresh)
self.activeDocument = instance.activeDocument()
self.activeInFile = self.activeDocument.fileName()

Expand Down Expand Up @@ -1009,7 +1010,10 @@ def handleMessage(self, msg):
self.setStatus('[Blender] ' + i18n(msg[1]))
else:
print("Received unrecognized message type from Blender: ", type)


def refresh(self):
self.activeDocument.refreshProjection()

def createAssistants(self):
(fileName, mime) = QFileDialog.getSaveFileName(self, i18n("Save File"), os.path.join(QStandardPaths.writableLocation(QStandardPaths.PicturesLocation), 'blenderlayer.paintingassistant'), i18n("Krita Assistant (*.paintingassistant)"))
if fileName:
Expand Down Expand Up @@ -1481,7 +1485,7 @@ def readSettings(self):
self.settings.convertBGR = instance.readSetting('blender_layer', 'convertBGR', 'True') == 'True'

self.settings.backgroundDraw = instance.readSetting('blender_layer', 'backgroundDraw', 'False') == 'True'
lockFramesStr = instance.readSetting('blender_layer', 'lockFrames', '')
lockFramesStr = instance.readSetting('blender_layer', 'lockFrames1', '')

try:
self.settings.port = int(portStr)
Expand All @@ -1500,7 +1504,7 @@ def readSettings(self):
try:
self.settings.lockFrames = int(lockFramesStr)
except ValueError:
self.settings.lockFrames = 10
self.settings.lockFrames = 1

def writeSettings(self):
instance.writeSetting('blender_layer', 'blenderPath', self.settings.blenderPath)
Expand All @@ -1518,4 +1522,4 @@ def writeSettings(self):
instance.writeSetting('blender_layer', 'colorManageBlender', str(self.settings.colorManageBlender))
instance.writeSetting('blender_layer', 'convertBGR', str(self.settings.convertBGR))
instance.writeSetting('blender_layer', 'backgroundDraw', str(self.settings.backgroundDraw))
instance.writeSetting('blender_layer', 'lockFrames', str(self.settings.lockFrames))
instance.writeSetting('blender_layer', 'lockFrames1', str(self.settings.lockFrames))
21 changes: 19 additions & 2 deletions blender_layer/blenderLayerServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class RunnableSignals(QObject):
connected = pyqtSignal(bool, object)
error = pyqtSignal(str)
msgReceived = pyqtSignal(object)
refresh = pyqtSignal()

class BlenderLayerServer(QRunnable):
def __init__(self, settings):
Expand All @@ -51,6 +52,7 @@ def run(self):
d = None
l = None
locked = False
refresh = False
framesLocked = 0

try:
Expand Down Expand Up @@ -192,7 +194,11 @@ def run(self):
l.setPixelData(QByteArray(msg[5]), x, y, w, h)
elif shm:
l.setPixelData(QByteArray(shm.buf.tobytes()), x, y, w, h)
d.refreshProjection()

if locked:
refresh = True
else:
self.signals.refresh.emit();
if modifiedSupported:
d.setModified(True)
elif msg[0] == 'updateFromFile' or msg[0] == 'updateFrameFromFile':
Expand Down Expand Up @@ -224,7 +230,10 @@ def run(self):
l.setPixelData(QByteArray(bytes(d.width() * d.height() * 4)), 0, 0, d.width(), d.height())

l.setPixelData(QByteArray.fromRawData(bits.asarray(frame.sizeInBytes())), x, y, w, h)
d.refreshProjection()
if locked:
refresh = True
else:
self.signals.refresh.emit();
else:
self.signals.error.emit(i18n("Warning: Failed to open a rendered frame"))
if modifiedSupported:
Expand Down Expand Up @@ -300,6 +309,10 @@ def run(self):
framesLocked = framesLocked + 1
if framesLocked >= self.settings.lockFrames:
d.unlock()
if refresh:
self.signals.refresh.emit();
#d.refreshProjection()
refresh = False
locked = False
framesLocked = 0

Expand Down Expand Up @@ -344,6 +357,10 @@ def run(self):
except Exception as e:
print(e)

if refresh:
d.refreshProjection()
refresh = False

try:
if s:
s.close()
Expand Down

0 comments on commit 6df69d2

Please sign in to comment.