Verified Commit 6db9e1c6 authored by Romain De Laage De Bellefaye's avatar Romain De Laage De Bellefaye 🌳
Browse files

Resolve segfault when reinitialize and init buffer

parent f68f69f7
......@@ -125,7 +125,7 @@ class Automate {
Reseau getReseauCourant() { return *itBuffer; }
/// initialiser le buffer s'il est vide avec un réseau
void initialiserBuffer() { buffer.clear(); buffer.push_front(reseauInit); }
void initialiserBuffer() { buffer.clear(); buffer.push_front(reseauInit); itBuffer = buffer.begin(); }
/// Définir le réseau initial de l'automate
void setReseauInit(Reseau& r) { reseauInit = r; h = r.getHauteur(); l = r.getLargeur(); }
......
......@@ -3,6 +3,7 @@
#include <reseau_cellule_etats.h>
#include <memory>
#include <QObject>
#include <QApplication>
#include <QPushButton>
......@@ -28,7 +29,7 @@ class AutoCell : public QWidget
{
static std::unique_ptr<AutoCell> instance;
Reseau* Grille = nullptr;
unique_ptr<Reseau> Grille = nullptr;
std::vector<QString> listeGrille;
Q_OBJECT
......
......@@ -40,11 +40,11 @@ void Automate::reinitialiserAutomate(){
delai = 500;
delete fonction;
delete regleVoisinage;
reseauInit = Reseau(0, 0);
buffer.clear();
itBuffer = buffer.begin();
h = 0;
l = 0;
reseauInit = Reseau(0, 0);
year = 2000;
author = "Anonym";
desc = "";
......
......@@ -213,8 +213,8 @@ void AutoCell::afficherGrille(Reseau* Grille)
{
win_grid = new QWidget;
unsigned int l = Grille->getLargeur();
unsigned int h = Grille->getHauteur();
int l = Grille->getLargeur();
int h = Grille->getHauteur();
delete grid;
grid = new QTableWidget(h,l,win_grid);
......@@ -280,9 +280,7 @@ void AutoCell::initialiserGrille(){
return;
}
delete Grille;
this->Grille = new Reseau(h,l);
this->Grille.reset(new Reseau(h,l));
if (check_aleatoire->isChecked())
Grille->setAleatoire();
......@@ -290,8 +288,7 @@ void AutoCell::initialiserGrille(){
QString nom_grille = list_grids->currentText();
if (check_load_grid->isChecked()) {
delete Grille;
Grille = new Reseau(Database::getInstance().getReseau(listeGrille[list_grids->currentIndex()*2].toInt())); /// Méthode à implémenter
this->Grille.reset(new Reseau(Database::getInstance().getReseau(listeGrille[list_grids->currentIndex()*2].toInt())));
QString str_largeur;
//str_largeur.setNum(listeGrille[list_grids->currentIndex()*2].toInt());
QString str_hauteur;
......@@ -303,10 +300,9 @@ void AutoCell::initialiserGrille(){
//réinitialiser l'automate
Automate::getInstance().reset();
this->afficherGrille(this->Grille);
this->afficherGrille(this->Grille.get());
Automate::getInstance().setReseauInit(*Grille);
Automate::getInstance().initialiserBuffer();
};
void AutoCell::RAZ(){
delete grid;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment