Skip to content

Commit 15e3134

Browse files
committed
Fix some problems related to memory consumption
1 parent 1e8303a commit 15e3134

9 files changed

Lines changed: 45 additions & 25 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Build Status](https://github.com/bow-simulation/virtualbow/actions/workflows/build.yml/badge.svg)
44

5-
VirtualBow software tool for designing and simulating bows.
5+
VirtualBow is a software tool for designing and simulating bows.
66
Visit http://www.virtualbow.org for more information about the project.
77

88
# Building
@@ -54,12 +54,12 @@ Contributions that fix issues with MSVC will be accepted.
5454
On Linux, the Qt libraries packaged with the system are used.
5555
On Ubuntu they can be installed with
5656

57-
sudo apt install qtbase5-dev
57+
sudo apt install qt6-base-dev
5858

5959
The rest of the build process is the same on Linux and MacOS
6060

6161
mkdir build && cd build
62-
cmake ../virtualbow -DCMAKE_TOOLCHAIN_FILE=[...]/paths.cmake -DCMAKE_BUILD_TYPE=Release
62+
cmake ../virtualbow/gui -DCMAKE_TOOLCHAIN_FILE=[...]/paths.cmake -DCMAKE_BUILD_TYPE=Release
6363
cmake --build .
6464

6565
# Contributing

gui/source/post/ResultWindow.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
#include "ResultWindow.hpp"
22
#include "OutputWidget.hpp"
33
#include "pre/utils/UserSettings.hpp"
4+
#include <QCloseEvent>
45
#include <QMenuBar>
56
#include <QMessageBox>
67
#include <QFileDialog>
78

8-
ResultWindow::ResultWindow(const QString& filePath, const BowResult& data) {
9+
ResultWindow::ResultWindow(const QString& filePath, const BowResult& data, QWidget* parent):
10+
QMainWindow(parent)
11+
{
912
// Main window properties
10-
this->setWindowFilePath(filePath);
11-
this->setWindowIcon(QIcon(":/icons/logo.svg"));
12-
this->setStyleSheet("QMainWindow { background-image:url(:/icons/background.png); background-position: center; background-repeat: no-repeat; }");
13-
this->menuBar()->setAutoFillBackground(true);
14-
this->resize({1000, 700}); // Initial size, overwritten by stored window geometry if present
13+
setWindowFilePath(filePath);
14+
setWindowIcon(QIcon(":/icons/logo.svg"));
15+
setStyleSheet("QMainWindow { background-image:url(:/icons/background.png); background-position: center; background-repeat: no-repeat; }");
16+
menuBar()->setAutoFillBackground(true);
17+
resize({1000, 700}); // Initial size, overwritten by stored window geometry if present
1518

1619
// Load state and geometry
1720
UserSettings settings;
@@ -21,16 +24,18 @@ ResultWindow::ResultWindow(const QString& filePath, const BowResult& data) {
2124
// Try to load output data
2225
try {
2326
this->data = data;
24-
this->setCentralWidget(new OutputWidget(this->data));
27+
setCentralWidget(new OutputWidget(this->data));
2528
}
2629
catch(const std::exception& e) {
2730
QMessageBox::critical(this, "Error", "Failed to open result data:\n" + QString(e.what()));
2831
}
2932
}
3033

31-
void ResultWindow::closeEvent(QCloseEvent *event) {
34+
void ResultWindow::closeEvent(QCloseEvent* event) {
3235
// Save state and geometry
3336
UserSettings settings;
3437
settings.setValue("OutputWindow/state", saveState());
3538
settings.setValue("OutputWindow/geometry", saveGeometry());
39+
40+
event->accept();
3641
}

gui/source/post/ResultWindow.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class RecentFilesMenu;
66

77
class ResultWindow: public QMainWindow {
88
public:
9-
ResultWindow(const QString& filePath, const BowResult& data);
9+
ResultWindow(const QString& filePath, const BowResult& data, QWidget* parent = nullptr);
1010

1111
private:
1212
BowResult data;

gui/source/pre/MainWindow.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ bool MainWindow::saveToFile(const QString& path) {
191191
}
192192
}
193193

194-
void MainWindow::closeEvent(QCloseEvent *event) {
194+
void MainWindow::closeEvent(QCloseEvent* event) {
195195
if(optionalSaveModifications()) {
196196
// Changes successfully saved or discarded
197197
// Continue closing, save window state and geometry
@@ -271,10 +271,10 @@ void MainWindow::runSimulation(Mode mode) {
271271
}
272272

273273
// Run Simulation, launch Post on results if successful
274-
BowResult result;
275-
SimulationDialog dialog(this, mainModel->getBow(), result, mode);
274+
SimulationDialog dialog(this, mainModel->getBow(), mode);
276275
if(dialog.exec() == QDialog::Accepted) {
277-
auto window = new ResultWindow(this->windowFilePath(), result);
276+
auto window = new ResultWindow(this->windowFilePath(), dialog.getResult(), this);
277+
window->setAttribute(Qt::WA_DeleteOnClose);
278278
window->show();
279279
}
280280
}

gui/source/pre/SimulationDialog.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
#include <QVBoxLayout>
44
#include <QProgressBar>
55
#include <QMessageBox>
6+
#include <QCloseEvent>
67
#include <QLabel>
78
#include <QProcess>
89
#include <QDialogButtonBox>
910
#include <QCoreApplication>
1011
#include <QDir>
1112
#include <cmath>
1213

13-
SimulationDialog::SimulationDialog(QWidget* parent, const BowModel& model, BowResult& result, Mode mode)
14+
SimulationDialog::SimulationDialog(QWidget* parent, const BowModel& model, Mode mode)
1415
: DialogBase(parent)
1516
{
1617
auto vbox = new QVBoxLayout();
@@ -95,6 +96,11 @@ SimulationDialog::SimulationDialog(QWidget* parent, const BowModel& model, BowRe
9596
watcher->setFuture(future);
9697
}
9798

98-
void SimulationDialog::closeEvent(QCloseEvent *event) {
99+
const BowResult& SimulationDialog::getResult() const {
100+
return result;
101+
}
102+
103+
void SimulationDialog::closeEvent(QCloseEvent* event) {
104+
event->accept();
99105
this->reject();
100106
}

gui/source/pre/SimulationDialog.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ class SimulationDialog: public DialogBase {
66
Q_OBJECT
77

88
public:
9-
SimulationDialog(QWidget* parent, const BowModel& model, BowResult& result, Mode mode);
9+
SimulationDialog(QWidget* parent, const BowModel& model, Mode mode);
10+
const BowResult& getResult() const;
1011

1112
signals:
1213
void staticProgressChanged(int);
1314
void dynamicProgressChanged(int);
1415

1516
private:
17+
BowResult result;
18+
1619
void closeEvent(QCloseEvent *event) override;
1720
};

gui/source/pre/models/PropertyListModel.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ColorProperty: public AbstractProperty {
4545

4646
virtual QVariant data(int role) const override {
4747
if(role == Qt::DisplayRole || role == Qt::EditRole ) {
48-
return QColor::fromString(value);
48+
return QColor(QString::fromStdString(value));
4949
}
5050

5151
return QVariant();

rust/virtualbow_ffi/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ mod api;
1313
pub struct Response {
1414
error: *mut c_char,
1515
data: *mut u8,
16-
size: usize
16+
size: usize,
17+
capacity: usize
1718
}
1819

1920
impl Response {
@@ -22,7 +23,8 @@ impl Response {
2223
Self {
2324
error: ptr::null_mut(),
2425
data: ptr::null_mut(),
25-
size: 0
26+
size: 0,
27+
capacity: 0
2628
}
2729
}
2830

@@ -33,7 +35,8 @@ impl Response {
3335
Self {
3436
error: message.into_raw(),
3537
data: ptr::null_mut(),
36-
size: 0
38+
size: 0,
39+
capacity: 0
3740
}
3841
}
3942

@@ -44,13 +47,15 @@ impl Response {
4447
fn data(mut bytes: Vec<u8>) -> Self {
4548
let data = bytes.as_mut_ptr();
4649
let size = bytes.len();
50+
let capacity = bytes.capacity();
4751

4852
std::mem::forget(bytes);
4953

5054
Self {
5155
error: ptr::null_mut(),
5256
data,
53-
size
57+
size,
58+
capacity
5459
}
5560
}
5661

@@ -60,7 +65,7 @@ impl Response {
6065
let _string = CString::from_raw(self.error);
6166
}
6267
if !self.data.is_null() {
63-
let _vector = Vec::from_raw_parts(self.data, self.size, self.size);
68+
let _vector = Vec::from_raw_parts(self.data, self.size, self.capacity);
6469
}
6570
}
6671
}

rust/virtualbow_ffi/virtualbow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct Response {
1919
char *error;
2020
uint8_t *data;
2121
uintptr_t size;
22+
uintptr_t capacity;
2223
};
2324

2425
extern "C" {

0 commit comments

Comments
 (0)