Skip to content

Commit e41ed96

Browse files
committed
Update to v0.50.18.
1 parent e94a32f commit e41ed96

File tree

215 files changed

+2188
-1510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+2188
-1510
lines changed

ClientSource/Connection/BotBase.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ BotBaseContext::BotBaseContext(CancellableScope& parent, BotBase& botbase)
2222
{
2323
attach(parent);
2424
}
25+
BotBaseContext::BotBaseContext(CancellableScope& parent, BotBaseContext& context)
26+
: m_botbase(context.botbase())
27+
{
28+
attach(parent);
29+
}
2530
BotBaseContext::~BotBaseContext(){
31+
m_lifetime_sanitizer.check_usage();
32+
try{
33+
m_botbase.wait_for_all_requests(this);
34+
}catch (...){}
2635
detach();
2736
}
2837

ClientSource/Connection/BotBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class BotBaseContext final : public CancellableScope{
7575
public:
7676
BotBaseContext(BotBase& botbase);
7777
BotBaseContext(CancellableScope& parent, BotBase& botbase);
78+
BotBaseContext(CancellableScope& parent, BotBaseContext& context);
7879
virtual ~BotBaseContext();
7980

8081

Common/Cpp/Concurrency/ScheduledTaskRunner.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,43 @@ ScheduledTaskRunner::~ScheduledTaskRunner(){
2020
// ScheduledTaskRunner::cancel(nullptr);
2121
{
2222
std::lock_guard<std::mutex> lg(m_lock);
23+
// cout << "ScheduledTaskRunner: (Destructor - start): " << this << endl;
2324
m_stopped = true;
2425
m_cv.notify_all();
2526
}
2627
m_runner.reset();
28+
// cout << "ScheduledTaskRunner: (Destructor - end): " << this << endl;
2729
}
2830
ScheduledTaskRunner::ScheduledTaskRunner(AsyncDispatcher& dispatcher)
2931
: m_stopped(false)
3032
, m_runner(dispatcher.dispatch([this]{ thread_loop(); }))
31-
{}
33+
{
34+
// cout << "ScheduledTaskRunner: (Constructor): " << this << endl;
35+
}
3236
size_t ScheduledTaskRunner::size() const{
3337
std::lock_guard<std::mutex> lg(m_lock);
3438
return m_schedule.size();
3539
}
3640
WallClock ScheduledTaskRunner::next_event() const{
3741
std::lock_guard<std::mutex> lg(m_lock);
38-
if (m_schedule.empty()){
42+
if (m_stopped || m_schedule.empty()){
3943
return WallClock::max();
4044
}
4145
return m_schedule.begin()->first;
4246
}
4347
void ScheduledTaskRunner::add_event(WallClock time, std::function<void()> callback){
4448
std::lock_guard<std::mutex> lg(m_lock);
49+
if (m_stopped){
50+
return;
51+
}
4552
m_schedule.emplace(time, std::move(callback));
4653
m_cv.notify_all();
4754
}
4855
void ScheduledTaskRunner::add_event(std::chrono::milliseconds time_from_now, std::function<void()> callback){
4956
std::lock_guard<std::mutex> lg(m_lock);
57+
if (m_stopped){
58+
return;
59+
}
5060
m_schedule.emplace(current_time() + time_from_now, std::move(callback));
5161
m_cv.notify_all();
5262
}
@@ -62,6 +72,7 @@ bool ScheduledTaskRunner::cancel(std::exception_ptr exception) noexcept{
6272
#endif
6373
void ScheduledTaskRunner::thread_loop(){
6474
std::unique_lock<std::mutex> lg(m_lock);
75+
// cout << "ScheduledTaskRunner: (Starting thread loop): " << this << endl;
6576
// WallClock last_check_timestamp = current_time();
6677
while (!m_stopped){
6778
#if 0
@@ -71,7 +82,9 @@ void ScheduledTaskRunner::thread_loop(){
7182
#endif
7283

7384
if (m_schedule.empty()){
85+
// cout << "ScheduledTaskRunner: (Sleeping): " << this << endl;
7486
m_cv.wait(lg);
87+
// cout << "ScheduledTaskRunner: (Waking): " << this << endl;
7588
continue;
7689
}
7790

@@ -81,11 +94,15 @@ void ScheduledTaskRunner::thread_loop(){
8194
m_cv.wait_until(lg, item->first);
8295
continue;
8396
}
97+
// cout << "ScheduledTaskRunner: (task - start): " << this << endl;
8498
lg.unlock();
8599
item->second();
86100
lg.lock();
101+
// cout << "ScheduledTaskRunner: (task - end): " << this << endl;
87102
m_schedule.erase(item);
88103
}
104+
// cout << "ScheduledTaskRunner: (Clearing schedule): " << this << endl;
105+
m_schedule.clear();
89106
}
90107

91108

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ file(GLOB MAIN_SOURCES
553553
Source/CommonFramework/Tools/SuperControlSession.h
554554
Source/CommonFramework/Tools/VideoResolutionCheck.cpp
555555
Source/CommonFramework/Tools/VideoResolutionCheck.h
556+
Source/CommonFramework/Tools/VideoStream.cpp
557+
Source/CommonFramework/Tools/VideoStream.h
556558
Source/CommonFramework/VideoPipeline/Backends/CameraImplementations.cpp
557559
Source/CommonFramework/VideoPipeline/Backends/CameraImplementations.h
558560
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt5.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ SOURCES += \
290290
Source/CommonFramework/Tools/StatsTracking.cpp \
291291
Source/CommonFramework/Tools/SuperControlSession.cpp \
292292
Source/CommonFramework/Tools/VideoResolutionCheck.cpp \
293+
Source/CommonFramework/Tools/VideoStream.cpp \
293294
Source/CommonFramework/VideoPipeline/Backends/CameraImplementations.cpp \
294295
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt5.cpp \
295296
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.cpp \
@@ -1388,6 +1389,7 @@ HEADERS += \
13881389
Source/CommonFramework/Tools/StatsTracking.h \
13891390
Source/CommonFramework/Tools/SuperControlSession.h \
13901391
Source/CommonFramework/Tools/VideoResolutionCheck.h \
1392+
Source/CommonFramework/Tools/VideoStream.h \
13911393
Source/CommonFramework/VideoPipeline/Backends/CameraImplementations.h \
13921394
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt5.h \
13931395
Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.h \

SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp

Lines changed: 85 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
#include "Common/Cpp/PrettyPrint.h"
1111
#include "Common/Cpp/Json/JsonArray.h"
1212
#include "Common/Cpp/Json/JsonObject.h"
13+
#include "Common/Cpp/Concurrency/AsyncDispatcher.h"
1314
#include "CommonFramework/Globals.h"
1415
#include "CommonFramework/GlobalSettingsPanel.h"
16+
#include "CommonFramework/GlobalServices.h"
1517
#include "CommonFramework/Logging/Logger.h"
1618
#include "CommonFramework/Notifications/ProgramNotifications.h"
1719
#include "CommonFramework/Environment/Environment.h"
1820
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
19-
#include "CommonFramework/Tools/ConsoleHandle.h"
21+
#include "CommonFramework/Recording/StreamHistorySession.h"
2022
#include "ProgramDumper.h"
2123
#include "ErrorReports.h"
2224

@@ -112,7 +114,7 @@ SendableErrorReport::SendableErrorReport(
112114
std::string title,
113115
std::vector<std::pair<std::string, std::string>> messages,
114116
const ImageViewRGB32& image,
115-
ConsoleHandle* console
117+
const StreamHistorySession* stream_history
116118
)
117119
: SendableErrorReport()
118120
{
@@ -145,8 +147,8 @@ SendableErrorReport::SendableErrorReport(
145147
file.flush();
146148
m_logs_name = ERROR_LOGS_NAME;
147149
}
148-
if (console){
149-
if (console->save_stream_history(m_directory + "Video.mp4")){
150+
if (stream_history){
151+
if (stream_history->save(m_directory + "Video.mp4")){
150152
m_video_name = "Video.mp4";
151153
}
152154
}
@@ -165,56 +167,63 @@ SendableErrorReport::SendableErrorReport(std::string directory)
165167
JsonValue json = load_json_file(m_directory + "Report.json");
166168
const JsonObject& obj = json.to_object_throw();
167169
m_timestamp = obj.get_string_throw("Timestamp");
168-
m_processor = obj.get_string_throw("Processor");
169-
m_program = obj.get_string_throw("Program");
170-
m_program_id = obj.get_string_throw("ProgramID");
171-
m_program_runtime_millis = obj.get_integer_throw("ElapsedTimeMillis");
172-
m_title = obj.get_string_throw("Title");
173-
{
174-
const JsonArray& messages = obj.get_array_throw("Messages");
175-
for (const JsonValue& message : messages){
176-
const JsonArray& item = message.to_array_throw();
177-
if (item.size() != 2){
178-
throw ParseException("Expected 2 values for message.");
170+
171+
// If we error from this point on, we'll just move it to the sent folder.
172+
try{
173+
m_processor = obj.get_string_throw("Processor");
174+
m_program = obj.get_string_throw("Program");
175+
m_program_id = obj.get_string_throw("ProgramID");
176+
m_program_runtime_millis = obj.get_integer_throw("ElapsedTimeMillis");
177+
m_title = obj.get_string_throw("Title");
178+
{
179+
const JsonArray& messages = obj.get_array_throw("Messages");
180+
for (const JsonValue& message : messages){
181+
const JsonArray& item = message.to_array_throw();
182+
if (item.size() != 2){
183+
throw ParseException("Expected 2 values for message.");
184+
}
185+
m_messages.emplace_back(
186+
item[0].to_string_throw(),
187+
item[1].to_string_throw()
188+
);
179189
}
180-
m_messages.emplace_back(
181-
item[0].to_string_throw(),
182-
item[1].to_string_throw()
183-
);
184190
}
185-
}
186-
{
187-
const std::string* image_name = obj.get_string("Screenshot");
188-
if (image_name){
189-
try{
190-
m_image_owner = ImageRGB32(m_directory + *image_name);
191-
m_image = m_image_owner;
192-
}catch (FileException&){}
191+
{
192+
const std::string* image_name = obj.get_string("Screenshot");
193+
if (image_name){
194+
try{
195+
m_image_owner = ImageRGB32(m_directory + *image_name);
196+
m_image = m_image_owner;
197+
}catch (FileException&){}
198+
}
193199
}
194-
}
195-
{
196-
const std::string* video_name = obj.get_string("Video");
197-
if (video_name){
198-
m_video_name = *video_name;
200+
{
201+
const std::string* video_name = obj.get_string("Video");
202+
if (video_name){
203+
m_video_name = *video_name;
204+
}
199205
}
200-
}
201-
{
202-
const std::string* dump_name = obj.get_string("Dump");
203-
if (dump_name){
204-
m_dump_name = *dump_name;
206+
{
207+
const std::string* dump_name = obj.get_string("Dump");
208+
if (dump_name){
209+
m_dump_name = *dump_name;
210+
}
205211
}
206-
}
207-
{
208-
const std::string* logs_name = obj.get_string("Logs");
209-
if (logs_name){
210-
m_logs_name = *logs_name;
212+
{
213+
const std::string* logs_name = obj.get_string("Logs");
214+
if (logs_name){
215+
m_logs_name = *logs_name;
216+
}
211217
}
212-
}
213-
{
214-
const JsonArray& files = obj.get_array_throw("Files");
215-
for (const JsonValue& file : files){
216-
m_files.emplace_back(file.to_string_throw());
218+
{
219+
const JsonArray& files = obj.get_array_throw("Files");
220+
for (const JsonValue& file : files){
221+
m_files.emplace_back(file.to_string_throw());
222+
}
217223
}
224+
}catch (...){
225+
move_to_sent();
226+
throw;
218227
}
219228
}
220229
void SendableErrorReport::add_file(std::string filename){
@@ -270,23 +279,22 @@ void SendableErrorReport::save(Logger* logger) const{
270279
report.dump(m_directory + "Report.json");
271280
}
272281

273-
#ifndef PA_OFFICIAL
274-
bool SendableErrorReport::send(Logger& logger){
275-
return false;
276-
}
277-
#endif
278-
279282
void SendableErrorReport::move_to_sent(){
280283
// cout << "move_to_sent()" << endl;
281284
QDir().mkdir(QString::fromStdString(ERROR_PATH_SENT));
282285

283286
std::string new_directory = ERROR_PATH_SENT + "/" + m_timestamp + "/";
284287
// cout << "old: " << m_directory << endl;
285288
// cout << "new: " << new_directory << endl;
286-
QDir().rename(
289+
bool success = QDir().rename(
287290
QString::fromStdString(m_directory),
288291
QString::fromStdString(new_directory)
289292
);
293+
if (success){
294+
global_logger_tagged().log("Moved error report " + m_timestamp + ".");
295+
}else{
296+
global_logger_tagged().log("Unable to move error report " + m_timestamp + ".", COLOR_RED);
297+
}
290298
m_directory = std::move(new_directory);
291299
}
292300

@@ -306,37 +314,46 @@ std::vector<std::string> SendableErrorReport::get_pending_reports(){
306314
return ret;
307315
}
308316

317+
#ifndef PA_OFFICIAL
318+
void SendableErrorReport::send(Logger& logger, std::shared_ptr<SendableErrorReport> report){}
319+
#endif
320+
309321

310322

323+
// Send all the reports. This function will return early and all the reports
324+
// will be sent asynchronously in the background.
311325
void send_reports(Logger& logger, const std::vector<std::string>& reports){
312326
for (const std::string& path : reports){
313327
try{
314-
SendableErrorReport report(path);
315-
report.send(logger);
328+
// static int c = 0;
329+
// cout << "Sending... " << c++ << endl;
330+
// std:::shared_ptr because it needs to take ownership for
331+
// destruction at a later time.
332+
SendableErrorReport::send(logger, std::make_shared<SendableErrorReport>(path));
316333
}catch (Exception& e){
317334
logger.log("Unable to send report: " + path + ", Message: " + e.to_str(), COLOR_RED);
318335
}catch (...){
319336
logger.log("Unable to send report: " + path, COLOR_RED);
320337
}
321338
}
322339
}
323-
void send_all_unsent_reports(Logger& logger, bool allow_prompt){
340+
std::unique_ptr<AsyncTask> send_all_unsent_reports(Logger& logger, bool allow_prompt){
324341
#ifdef PA_OFFICIAL
325342
ErrorReportSendMode mode = GlobalSettings::instance().ERROR_REPORTS->SEND_MODE;
326343
if (mode == ErrorReportSendMode::NEVER_SEND_ANYTHING){
327-
return;
344+
return nullptr;
328345
}
329346

330347
std::vector<std::string> reports = SendableErrorReport::get_pending_reports();
331348
global_logger_tagged().log("Found " + std::to_string(reports.size()) + " unsent error reports.", COLOR_PURPLE);
332349

333350
if (reports.empty()){
334-
return;
351+
return nullptr;
335352
}
336353

337354
if (mode == ErrorReportSendMode::PROMPT_WHEN_CONVENIENT){
338355
if (!allow_prompt){
339-
return;
356+
return nullptr;
340357
}
341358
QMessageBox box;
342359
QMessageBox::StandardButton button = box.information(
@@ -356,13 +373,17 @@ void send_all_unsent_reports(Logger& logger, bool allow_prompt){
356373
QMessageBox::StandardButton::Yes
357374
);
358375
if (button != QMessageBox::StandardButton::Yes){
359-
return;
376+
return nullptr;
360377
}
361378
}
362379

363380
global_logger_tagged().log("Attempting to send " + std::to_string(reports.size()) + " error reports.", COLOR_PURPLE);
364-
send_reports(global_logger_tagged(), reports);
365381

382+
return global_async_dispatcher().dispatch([reports = std::move(reports)]{
383+
send_reports(global_logger_tagged(), reports);
384+
});
385+
#else
386+
return nullptr;
366387
#endif
367388
}
368389

@@ -372,7 +393,7 @@ void report_error(
372393
std::string title,
373394
std::vector<std::pair<std::string, std::string>> messages,
374395
const ImageViewRGB32& image,
375-
ConsoleHandle* console,
396+
const StreamHistorySession* stream_history,
376397
const std::vector<std::string>& files
377398
){
378399
if (logger == nullptr){
@@ -386,7 +407,7 @@ void report_error(
386407
std::move(title),
387408
std::move(messages),
388409
image,
389-
console
410+
stream_history
390411
);
391412

392413
std::vector<std::string> full_file_paths;

0 commit comments

Comments
 (0)