wip: heap corruption (3rd item main volume)

This commit is contained in:
Hane 2023-09-10 21:58:01 +02:00
commit 14fae226bc
6 changed files with 107 additions and 52 deletions

View file

@ -1,7 +1,8 @@
#include "qtclasses.h"
EndpointWidgetEvent::EndpointWidgetEvent(QEvent::Type type, int idx) : QEvent(type){
this->idx = idx;
template <typename T>
EndpointWidgetEvent<T>::EndpointWidgetEvent(QEvent::Type type, T payload) : QEvent(type){
this->payload = payload;
}
void ExtendedCheckBox::customEvent(QEvent* ev) {
@ -28,11 +29,13 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
//todo: based on qgridlayout, name+mute should be its own widget, same with channels
this->idx = idx;
this->eph = eph;
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ACTIVE, idx);
//todo: sussy
this->eph->setState(EndpointState::ENDPOINT_ACTIVE, idx);
layout = new QGridLayout(this);
//this->setLayout(layout);
log_debugcpp("epw main layout parent: " + std::to_string((intptr_t)(layout->parent())));
if (parent == nullptr) { log_debugcpp("owo?"); }
if (parent == nullptr) { log_debugcpp("ayooooo?"); }
defaultRolesCheckBoxes = {
{Roles::ROLE_ALL, new ExtendedCheckBox(this)},
@ -183,31 +186,44 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
log_debugcpp("ENDPOINT_WIDGETED");
}
EndpointWidget::~EndpointWidget() {
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ALL, INT_MAX);
}
void MainWindow::customEvent(QEvent* ev) {
if (ev->type() == CustomQEvent::EndpointWidgetObsolete) {
ev->setAccepted(true);
this->removeEndpointWidget((EndpointWidgetEvent*)ev);
this->removeEndpointWidget((EndpointWidgetEvent<uint64_t>*)ev);
return;
}
} else if (ev->type() == (QEvent::Type)CustomQEvent::EndpointWidgetCreated) {
ev->setAccepted(true);
this->addEndpointWidget((EndpointWidgetEvent<EndpointHandler*>*)ev);
}
// Make sure the rest of events are handled
QMainWindow::customEvent(ev);
}
void MainWindow::removeEndpointWidget(EndpointWidgetEvent* ev){
uint64_t i = ev->idx;
void MainWindow::removeEndpointWidget(EndpointWidgetEvent<uint64_t>* ev){
uint64_t i = ev->payload;
this->ews.at(i)->setParent(nullptr);
this->layout->removeWidget(ews.at(i));
uint64_t saisu = ews.size();
//delete ews.at(index);
while ((i + 1) < ews.size()) {
ews.at(i) = ews.at(i + 1);
ews.at(i)->updateEndpointHandlerFrontInfo(i);
ews.at(i)->updateEndpointHandlerFrontIndex(i);
i++;
}
ews.pop_back();
return;
}
void MainWindow::addEndpointWidget(EndpointWidgetEvent<EndpointHandler*>* ev){
EndpointWidget* epw = new EndpointWidget(this->ews.size(), ev->payload, widget);
this->layout->addWidget(epw);
ews.push_back(epw);
return;
}
void EndpointWidget::updateMute(int checked){
bool muted = (checked == 2 ? true : false);
@ -254,7 +270,7 @@ EndpointHandler* EndpointWidget::getEndpointHandler(){
return this->eph;
}
void EndpointWidget::updateEndpointHandlerFrontInfo(uint64_t index){
void EndpointWidget::updateEndpointHandlerFrontIndex(uint64_t index){
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ACTIVE, index);
}
@ -275,6 +291,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
* Registering needed custom events
*/
QEvent::registerEventType(CustomQEvent::EndpointWidgetObsolete);
QEvent::registerEventType(CustomQEvent::EndpointWidgetCreated);
QEvent::registerEventType(CustomQEvent::EndpointDefaultChange);
widget = new QWidget();
@ -348,20 +365,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
});
osh->setRemoveEndpointWidgetFunction([this](uint64_t index) {
EndpointWidgetEvent* removeObsoleteEndpointWidget = new EndpointWidgetEvent((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index);
QCoreApplication::instance()->postEvent(this, removeObsoleteEndpointWidget);
QCoreApplication::instance()->postEvent(this, new EndpointWidgetEvent<uint64_t>((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index));
});
/*
* osh->setReviseEndpointShowingFunction([this](std::wstring endpointId, Roles role){
*
*
* });
*/
osh->setAddEndpointWidgetFunction([this](EndpointHandler* eph) {
QCoreApplication::instance()->postEvent(this, new EndpointWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph));
});
}
void MainWindow::closeEvent(QCloseEvent *event) {
if (!event->spontaneous() || !isVisible()) return;
@ -389,7 +400,7 @@ void MainWindow::reloadEndpointWidgets() {
for (size_t epwIndex = 0; i < (osh->getEndpointHandlers().size()); i++) {
if (osh->getEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){
log_debugcpp("EPWidget creation");
osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid();
//osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid();
EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getEndpointHandlers().at(i), widget);
epwIndex++;
//alfinal estoes solopara inicializarlmao