This is why I needed bug testing

Fix a race condition and logic error
This commit is contained in:
ArsenArsen 2017-06-13 18:23:33 +02:00
parent 394ae45187
commit dde6fc0786
5 changed files with 16 additions and 3 deletions

View File

@ -100,6 +100,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ctx->finalizer = format->getFinalizer(); ctx->finalizer = format->getFinalizer();
ctx->validator = format->getValidator(); ctx->validator = format->getValidator();
ctx->format = format->getFormat(); ctx->format = format->getFormat();
ctx->postUploadTask = format->getPostUploadTask();
ctx->anotherFormat = format->getAnotherFormat(); ctx->anotherFormat = format->getAnotherFormat();
controller->start(ctx); controller->start(ctx);
}); });

View File

@ -42,6 +42,7 @@ bool RecordingController::end() {
_QueueContext contx; _QueueContext contx;
contx.arr = _context->finalizer(); contx.arr = _context->finalizer();
contx.format = _context->anotherFormat; contx.format = _context->anotherFormat;
contx.postUploadTask = _context->postUploadTask;
queue(contx); queue(contx);
}; };
c->targetFormat = QImage::Format_Alpha8; c->targetFormat = QImage::Format_Alpha8;
@ -94,6 +95,7 @@ void RecordingController::timeout() {
if (!uploadQueue.isEmpty()) { if (!uploadQueue.isEmpty()) {
auto a = uploadQueue.dequeue(); auto a = uploadQueue.dequeue();
UploaderSingleton::inst().upload(a.arr, a.format); UploaderSingleton::inst().upload(a.arr, a.format);
if (a.postUploadTask) a.postUploadTask();
} }
} }
} }

View File

@ -17,12 +17,14 @@ struct RecordingContext {
std::function<void(QImage)> consumer; std::function<void(QImage)> consumer;
std::function<bool(QSize)> validator; std::function<bool(QSize)> validator;
std::function<QByteArray()> finalizer; std::function<QByteArray()> finalizer;
std::function<void()> postUploadTask;
QString anotherFormat; QString anotherFormat;
}; };
struct _QueueContext { struct _QueueContext {
QByteArray arr; QByteArray arr;
QString format; QString format;
std::function<void()> postUploadTask;
}; };
class RecordingController : public QObject { class RecordingController : public QObject {

View File

@ -38,8 +38,6 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
return QByteArray(); return QByteArray();
} }
QByteArray data = res.readAll(); QByteArray data = res.readAll();
tmpDir.removeRecursively();
QScopedPointer<RecordingFormats>(this);
return data; return data;
}; };
validator = [&](QSize s) { validator = [&](QSize s) {
@ -61,7 +59,7 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
return true; return true;
}; };
consumer = [&](QImage img) { consumer = [&](QImage img) {
if (interrupt) try { if (!interrupt) try {
enc->addFrame(img); enc->addFrame(img);
} catch (std::runtime_error e) { } catch (std::runtime_error e) {
notifications::notify("KShare Video Encoder Error", e.what(), QSystemTrayIcon::Critical); notifications::notify("KShare Video Encoder Error", e.what(), QSystemTrayIcon::Critical);
@ -69,6 +67,10 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
interrupt = true; interrupt = true;
} }
}; };
postUploadTask = [&] {
tmpDir.removeRecursively();
QScopedPointer<RecordingFormats> th(this);
};
anotherFormat = formats::recordingFormatName(f); anotherFormat = formats::recordingFormatName(f);
} }
@ -80,6 +82,10 @@ std::function<QByteArray()> RecordingFormats::getFinalizer() {
return finalizer; return finalizer;
} }
std::function<void()> RecordingFormats::getPostUploadTask() {
return postUploadTask;
}
std::function<bool(QSize)> RecordingFormats::getValidator() { std::function<bool(QSize)> RecordingFormats::getValidator() {
return validator; return validator;
} }

View File

@ -16,6 +16,7 @@ public:
std::function<void(QImage)> getConsumer(); std::function<void(QImage)> getConsumer();
std::function<bool(QSize)> getValidator(); std::function<bool(QSize)> getValidator();
std::function<QByteArray()> getFinalizer(); std::function<QByteArray()> getFinalizer();
std::function<void()> getPostUploadTask();
QImage::Format getFormat(); QImage::Format getFormat();
QString getAnotherFormat(); QString getAnotherFormat();
@ -23,6 +24,7 @@ private:
std::function<void(QImage)> consumer; std::function<void(QImage)> consumer;
std::function<bool(QSize)> validator; std::function<bool(QSize)> validator;
std::function<QByteArray()> finalizer; std::function<QByteArray()> finalizer;
std::function<void()> postUploadTask;
std::vector<QImage> frames; std::vector<QImage> frames;
QImage::Format iFormat; QImage::Format iFormat;
QDir tmpDir; QDir tmpDir;