mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-24 10:02:08 +08:00
cabana: fix PandaStream crash if no panda found (#27948)
old-commit-hash: dc4b7b37c0
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "tools/cabana/streams/devicestream.h"
|
||||
|
||||
DeviceStream::DeviceStream(QObject *parent, QString address) : zmq_address(address), LiveStream(parent) {
|
||||
startStreamThread();
|
||||
}
|
||||
|
||||
void DeviceStream::streamThread() {
|
||||
|
||||
@@ -8,10 +8,15 @@ LiveStream::LiveStream(QObject *parent) : AbstractStream(parent, true) {
|
||||
util::create_directories(path, 0755);
|
||||
fs.reset(new std::ofstream(path + "/rlog" , std::ios::binary | std::ios::out));
|
||||
}
|
||||
|
||||
stream_thread = new QThread(this);
|
||||
QObject::connect(stream_thread, &QThread::started, [=]() { streamThread(); });
|
||||
QObject::connect(stream_thread, &QThread::finished, stream_thread, &QThread::deleteLater);
|
||||
}
|
||||
|
||||
void LiveStream::startStreamThread() {
|
||||
// delay the start of the thread to avoid calling startStreamThread
|
||||
// in the constructor when other classes' slots have not been connected to
|
||||
// the signals of the livestream.
|
||||
QTimer::singleShot(0, [this]() { stream_thread->start(); });
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
double getSpeed() override { return speed_; }
|
||||
bool isPaused() const override { return pause_; }
|
||||
void pause(bool pause) override;
|
||||
void startStreamThread();
|
||||
|
||||
protected:
|
||||
virtual void handleEvent(Event *evt);
|
||||
|
||||
@@ -13,6 +13,7 @@ PandaStream::PandaStream(QObject *parent, PandaStreamConfig config_) : config(co
|
||||
if (!connect()) {
|
||||
throw std::runtime_error("Failed to connect to panda");
|
||||
}
|
||||
startStreamThread();
|
||||
}
|
||||
|
||||
bool PandaStream::connect() {
|
||||
|
||||
Reference in New Issue
Block a user