fixed heap corruption

This commit is contained in:
Hane 2024-04-13 18:28:20 +02:00
commit 621841e954
2 changed files with 24 additions and 43 deletions

View file

@ -78,6 +78,7 @@ QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) {
void MainWindow::calculateChildWidgetsSize() { void MainWindow::calculateChildWidgetsSize() {
//We need dynamically added child widgets to expand so that we know their height //We need dynamically added child widgets to expand so that we know their height
//todo: own function + setsizeposition refactor + update setWidth bodies
screen = this->getCurrentScreen(); screen = this->getCurrentScreen();
log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString()); log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString());
QRect screenRes = screen->geometry(); QRect screenRes = screen->geometry();
@ -88,19 +89,8 @@ void MainWindow::calculateChildWidgetsSize() {
width = (uint64_t)std::abs(srx2) * this->widthRatio; width = (uint64_t)std::abs(srx2) * this->widthRatio;
log_debugcpp("Window Width: " + std::to_string(width)); log_debugcpp("Window Width: " + std::to_string(width));
for (auto *ew : ews) { for (auto *ew : ews) {
ew->setWidth(width, widthRatio); if (ew) ew->setWidth(width, widthRatio);
} }
/*
* sessionwidget: mainLabel, mainSlider, muteButton
* endpointwidget: mainLabel
*
*
*
*
*
*
*
*/
this->setAttribute(Qt::WA_DontShowOnScreen, true); this->setAttribute(Qt::WA_DontShowOnScreen, true);
this->show(); this->show();
@ -111,9 +101,7 @@ void MainWindow::calculateChildWidgetsSize() {
int height = 0; int height = 0;
for (auto *epw : this->ews) { for (auto *epw : this->ews) {
height += epw->height(); height += epw->height();
//width = (epw->width() > width) ? epw->width() : width;
} }
//width = scrollArea->width();
height += mainMenuBar->height(); height += mainMenuBar->height();
height += hw->height(); height += hw->height();
@ -138,7 +126,7 @@ QScreen* MainWindow::getCurrentScreen() {
return QGuiApplication::primaryScreen(); return QGuiApplication::primaryScreen();
} }
SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) : QWidget(parent), widthSpacer(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum){ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) : QWidget(parent) {
//todo: based on qgridlayout, name+mute should be its own widget, same with channels //todo: based on qgridlayout, name+mute should be its own widget, same with channels
this->idx = idx; this->idx = idx;
this->sh = sh; this->sh = sh;
@ -174,15 +162,8 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
log_debugcpp("SESSION SET WITH VOLUME " + std::to_string(volume)); log_debugcpp("SESSION SET WITH VOLUME " + std::to_string(volume));
//tip: would need to be new widget with layout in it //tip: would need to be new widget with layout in it
//mainMuteLayout = new QGridLayout(); widthSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
/* widgetLayout->addItem(widthSpacer);
* layout->addWidget(mainLabel, 0, 0, Qt::AlignLeft | Qt::AlignBottom);
* layout->addWidget(muteButton, 0, 1, Qt::AlignLeft | Qt::AlignBottom);
* layout->addWidget(mainSlider, 0, 2, 1, 2);
*
* layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
*/
widgetLayout->addItem(&widthSpacer);
widgetLayout->addWidget(mainLabel, Qt::AlignLeft | Qt::AlignBottom); widgetLayout->addWidget(mainLabel, Qt::AlignLeft | Qt::AlignBottom);
widgetLayout->addWidget(muteButton, Qt::AlignRight | Qt::AlignBottom); widgetLayout->addWidget(muteButton, Qt::AlignRight | Qt::AlignBottom);
widgetLayout->addWidget(mainSlider, Qt::AlignRight | Qt::AlignBottom); widgetLayout->addWidget(mainSlider, Qt::AlignRight | Qt::AlignBottom);
@ -196,7 +177,7 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
/* /*
* Session Volume Polling * Session Volume Polling
*/ */
volumePoller = new QTimer(); volumePoller = new QTimer(this);
connect(volumePoller, &QTimer::timeout, [this, sh](){ connect(volumePoller, &QTimer::timeout, [this, sh](){
//if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW. //if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW.
//todo: global + constexpr + ratio //todo: global + constexpr + ratio
@ -225,7 +206,7 @@ void SessionWidget::setWidth(uint64_t width, double widthRatio) {
this->muteButton->setMaximumWidth((int)(width * 0.10) /*1/32th 1080p*/); this->muteButton->setMaximumWidth((int)(width * 0.10) /*1/32th 1080p*/);
this->muteButton->setMinimumWidth((int)(width * 0.10) /*1/32th 1080p*/); this->muteButton->setMinimumWidth((int)(width * 0.10) /*1/32th 1080p*/);
this->mainSlider->setMinimumWidth((int)(width * 0.30) /*1/16 1080p*/); this->mainSlider->setMinimumWidth((int)(width * 0.30) /*1/16 1080p*/);
widthSpacer.changeSize((int)width * 0.20, 1, QSizePolicy::Expanding, QSizePolicy::Minimum /*200*/); widthSpacer->changeSize((int)width * 0.20, 1, QSizePolicy::Expanding, QSizePolicy::Minimum /*200*/);
} }
void SessionWidget::updateMute(int checked){ void SessionWidget::updateMute(int checked){
@ -240,7 +221,7 @@ void SessionWidget::updateMainVolume(int newValue){
SessionWidget::~SessionWidget() { SessionWidget::~SessionWidget() {
volumePoller->stop(); volumePoller->stop();
delete volumePoller; // volumePoller;
} }
ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidget *parent) : QWidget(parent){ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidget *parent) : QWidget(parent){
@ -435,8 +416,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
sessionWidgets.push_back(sessionWidget); sessionWidgets.push_back(sessionWidget);
eph->getSessionHandlers().at(i)->setFrontIndex(i); eph->getSessionHandlers().at(i)->setFrontIndex(i);
} }
/* This spacer provides proper spacing when window vertically > widgets */
//widgetLayout->addItem(&lastRowSpacer, row, 0);
/* Add/Remove SessionWidget callback */ /* Add/Remove SessionWidget callback */
eph->setAddSessionWidgetFunction([this](SessionHandler* sessionHandler) { eph->setAddSessionWidgetFunction([this](SessionHandler* sessionHandler) {
@ -455,6 +435,8 @@ void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
SessionWidget* sw = new SessionWidget(index, ev->payload, this); SessionWidget* sw = new SessionWidget(index, ev->payload, this);
ev->payload->setFrontIndex(index); ev->payload->setFrontIndex(index);
this->widgetLayout->addWidget(sw, row, 0, 1, 4); this->widgetLayout->addWidget(sw, row, 0, 1, 4);
//sw->hide();
//sw->show();
row++; row++;
sessionWidgets.push_back(sw); sessionWidgets.push_back(sw);
return; return;
@ -462,9 +444,11 @@ void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
void EndpointWidget::removeSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){ void EndpointWidget::removeSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
uint64_t i = ev->payload->getFrontIndex(); uint64_t i = ev->payload->getFrontIndex();
this->sessionWidgets.at(i)->setParent(nullptr); SessionWidget* deceased = sessionWidgets.at(i);
this->widgetLayout->removeWidget(sessionWidgets.at(i)); deceased->setParent(nullptr);
delete sessionWidgets.at(i); deceased->hide();
this->widgetLayout->removeWidget(deceased);
delete deceased;
sessionWidgets.at(i) = nullptr; sessionWidgets.at(i) = nullptr;
ev->payload->setFrontIndex(INT_MAX); ev->payload->setFrontIndex(INT_MAX);
//this->sessionWidgetsUpdateTimer->start(); //this->sessionWidgetsUpdateTimer->start();
@ -554,7 +538,7 @@ void EndpointWidget::setWidth(uint64_t width, double widthRatio) {
this->mainLabel->setMaximumWidth((int)width * 0.35 /* 1080p 120%*/); this->mainLabel->setMaximumWidth((int)width * 0.35 /* 1080p 120%*/);
this->mainLabel->setMinimumWidth((int)width * 0.35 /* 1080p 120%*/); this->mainLabel->setMinimumWidth((int)width * 0.35 /* 1080p 120%*/);
for (auto sw : sessionWidgets){ for (auto sw : sessionWidgets){
sw->setWidth(width, widthRatio); if (sw) sw->setWidth(width, widthRatio);
} }
} }
@ -642,7 +626,7 @@ HeaderWidget::HeaderWidget(QWidget *parent) : QWidget(parent) {
this->setLayout(widgetLayout); this->setLayout(widgetLayout);
} }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), lastRowSpacer(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding) { MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
//setWindowState(Qt::WindowFullScreen); //setWindowState(Qt::WindowFullScreen);
//setCentralWidget(centralWidget); //setCentralWidget(centralWidget);
//todo: ratio //todo: ratio
@ -661,11 +645,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), lastRowSpacer(1,
QEvent::registerEventType(CustomQEvent::EndpointDefaultChange); QEvent::registerEventType(CustomQEvent::EndpointDefaultChange);
QEvent::registerEventType(CustomQEvent::SessionWidgetObsolete); QEvent::registerEventType(CustomQEvent::SessionWidgetObsolete);
QEvent::registerEventType(CustomQEvent::SessionWidgetCreated); QEvent::registerEventType(CustomQEvent::SessionWidgetCreated);
;
//setWindowFlags(Qt::FramelessWindowHint); /* This spacer provides proper spacing when window vertically > widgets. */
//setParent(0); // Create TopLevel-Widget lastRowSpacer = new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
//setAttribute(Qt::WA_NoSystemBackground, true);
//setAttribute(Qt::WA_TranslucentBackground, true);
ewsUpdateTimer = new QTimer(this); ewsUpdateTimer = new QTimer(this);
widget = new QWidget(); widget = new QWidget();
widgetLayout = new QGridLayout(); widgetLayout = new QGridLayout();
@ -815,6 +797,6 @@ void MainWindow::reloadEndpointWidgets() {
//todo:: tas aqui tirao, no me gustas y probablemente yo a ti tampoco //todo:: tas aqui tirao, no me gustas y probablemente yo a ti tampoco
//seguramente falle al querer rematar esto con redimensionar la ventana sólo //seguramente falle al querer rematar esto con redimensionar la ventana sólo
//con los default endpoints en vista //con los default endpoints en vista
widgetLayout->addItem(&lastRowSpacer, i, 0); widgetLayout->addItem(lastRowSpacer, i, 0);
} }

View file

@ -98,8 +98,7 @@ private:
QCheckBox *muteButton = nullptr; QCheckBox *muteButton = nullptr;
SessionHandler* sh; SessionHandler* sh;
QTimer* volumePoller = nullptr; QTimer* volumePoller = nullptr;
QSpacerItem* widthSpacer;
QSpacerItem widthSpacer;
}; };
class ChannelWidget : public QWidget { class ChannelWidget : public QWidget {
@ -241,7 +240,7 @@ private:
//todo: ratio //todo: ratio
//Win10 1080p 120% //Win10 1080p 120%
QSize mwSize; QSize mwSize;
QSpacerItem lastRowSpacer; QSpacerItem* lastRowSpacer;
//public slots: //public slots: