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->validator = format->getValidator();
ctx->format = format->getFormat();
ctx->postUploadTask = format->getPostUploadTask();
ctx->anotherFormat = format->getAnotherFormat();
controller->start(ctx);
});

View File

@ -42,6 +42,7 @@ bool RecordingController::end() {
_QueueContext contx;
contx.arr = _context->finalizer();
contx.format = _context->anotherFormat;
contx.postUploadTask = _context->postUploadTask;
queue(contx);
};
c->targetFormat = QImage::Format_Alpha8;
@ -94,6 +95,7 @@ void RecordingController::timeout() {
if (!uploadQueue.isEmpty()) {
auto a = uploadQueue.dequeue();
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<bool(QSize)> validator;
std::function<QByteArray()> finalizer;
std::function<void()> postUploadTask;
QString anotherFormat;
};
struct _QueueContext {
QByteArray arr;
QString format;
std::function<void()> postUploadTask;
};
class RecordingController : public QObject {

View File

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

View File

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