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() {
//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();
log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString());
QRect screenRes = screen->geometry();
@ -88,19 +89,8 @@ void MainWindow::calculateChildWidgetsSize() {
width = (uint64_t)std::abs(srx2) * this->widthRatio;
log_debugcpp("Window Width: " + std::to_string(width));
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->show();
@ -111,9 +101,7 @@ void MainWindow::calculateChildWidgetsSize() {
int height = 0;
for (auto *epw : this->ews) {
height += epw->height();
//width = (epw->width() > width) ? epw->width() : width;
}
//width = scrollArea->width();
height += mainMenuBar->height();
height += hw->height();
@ -138,7 +126,7 @@ QScreen* MainWindow::getCurrentScreen() {
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
this->idx = idx;
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));
//tip: would need to be new widget with layout in it
//mainMuteLayout = new QGridLayout();
/*
* 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);
widthSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
widgetLayout->addItem(widthSpacer);
widgetLayout->addWidget(mainLabel, Qt::AlignLeft | Qt::AlignBottom);
widgetLayout->addWidget(muteButton, 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
*/
volumePoller = new QTimer();
volumePoller = new QTimer(this);
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.
//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->setMinimumWidth((int)(width * 0.10) /*1/32th 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){
@ -240,7 +221,7 @@ void SessionWidget::updateMainVolume(int newValue){
SessionWidget::~SessionWidget() {
volumePoller->stop();
delete volumePoller;
// volumePoller;
}
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);
eph->getSessionHandlers().at(i)->setFrontIndex(i);
}
/* This spacer provides proper spacing when window vertically > widgets */
//widgetLayout->addItem(&lastRowSpacer, row, 0);
/* Add/Remove SessionWidget callback */
eph->setAddSessionWidgetFunction([this](SessionHandler* sessionHandler) {
@ -455,6 +435,8 @@ void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
SessionWidget* sw = new SessionWidget(index, ev->payload, this);
ev->payload->setFrontIndex(index);
this->widgetLayout->addWidget(sw, row, 0, 1, 4);
//sw->hide();
//sw->show();
row++;
sessionWidgets.push_back(sw);
return;
@ -462,9 +444,11 @@ void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
void EndpointWidget::removeSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
uint64_t i = ev->payload->getFrontIndex();
this->sessionWidgets.at(i)->setParent(nullptr);
this->widgetLayout->removeWidget(sessionWidgets.at(i));
delete sessionWidgets.at(i);
SessionWidget* deceased = sessionWidgets.at(i);
deceased->setParent(nullptr);
deceased->hide();
this->widgetLayout->removeWidget(deceased);
delete deceased;
sessionWidgets.at(i) = nullptr;
ev->payload->setFrontIndex(INT_MAX);
//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->setMinimumWidth((int)width * 0.35 /* 1080p 120%*/);
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);
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), lastRowSpacer(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding) {
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
//setWindowState(Qt::WindowFullScreen);
//setCentralWidget(centralWidget);
//todo: ratio
@ -661,11 +645,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), lastRowSpacer(1,
QEvent::registerEventType(CustomQEvent::EndpointDefaultChange);
QEvent::registerEventType(CustomQEvent::SessionWidgetObsolete);
QEvent::registerEventType(CustomQEvent::SessionWidgetCreated);
//setWindowFlags(Qt::FramelessWindowHint);
//setParent(0); // Create TopLevel-Widget
//setAttribute(Qt::WA_NoSystemBackground, true);
//setAttribute(Qt::WA_TranslucentBackground, true);
;
/* This spacer provides proper spacing when window vertically > widgets. */
lastRowSpacer = new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
ewsUpdateTimer = new QTimer(this);
widget = new QWidget();
widgetLayout = new QGridLayout();
@ -815,6 +797,6 @@ void MainWindow::reloadEndpointWidgets() {
//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
//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;
SessionHandler* sh;
QTimer* volumePoller = nullptr;
QSpacerItem widthSpacer;
QSpacerItem* widthSpacer;
};
class ChannelWidget : public QWidget {
@ -241,7 +240,7 @@ private:
//todo: ratio
//Win10 1080p 120%
QSize mwSize;
QSpacerItem lastRowSpacer;
QSpacerItem* lastRowSpacer;
//public slots: