Exception Read violation in destructor, QT / C++

-4

I am trying to initialise a new "neuralnetwork" object and it its constructor i call iniStandardSettings. (so far so good)

From there my code crashes with follwing Exception line:

:-1: error: Debugger encountered an exception: Exception at 0x503ad6bb, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)

When i googled i found alot stuff about overloading the "=" operator for initialising my class "Settings".

From my debugger i can tell that there is a "Settings" Object in the subSettings of networkSettings.

So i am not certain if this is a problem of copying/initialisation or destruction because my class "Settings" does contains a vector of other Settings and destructor is then recurrent (?) .

I really hope, someone can help me . Tell me if you need some further information.

greetings and thanks in advance.

call of settings constructor and destructor

(define settings for overall network + adding the settings for all layers)

void NeuralNetwork::iniStandardSettings(){
    int stdSize = 2;
    int stdNperL = 3;
    networkSettings.integerSettings.insert({"layerCount",stdSize});
    networkSettings.integerSettings.insert({"inputLayerIndex",0});
    networkSettings.integerSettings.insert({"outputLayerIndex",stdSize-1});
    networkSettings.stringSettings.insert({"networkType","matrix"});
    networkSettings.stringSettings.insert({"backpropagationType","simple"});
    networkSettings.doubleSettings.insert({"learnrate",0.1});
    networkSettings.stringSettings.insert({"activationFunction","tanh"});
    this->networkType = &networkSettings.stringSettings.at("networkType");
    for(int i=0;i<stdSize;i++){
        Settings *s = new Settings();
//        s = &networkSettings;
        s->integerSettings.insert({"layerCount",stdNperL});
        layerSettings.push_back(*s);
    }
}

Settings.h

#ifndef SETTINGS_H
#define SETTINGS_H

#include <QTabWidget>
#include <map>
#include <QTableWidgetItem>

using namespace std;

namespace Ui {
class Settings;
}

class Settings : public QTabWidget
{
    Q_OBJECT

signals:

    void clicked();


public:


    map<string,QString> stringSettings;
    map<string, int > integerSettings;
    map<string, long long> longSettings;
    map<string, double> doubleSettings;
    map<string, bool> booleanSettings;
    vector<Settings> subSettings;

    explicit Settings(QWidget *parent = 0);
    Settings(const Settings& s);

    Settings &operator =(Settings &s);
    Settings* operator=(Settings *s);

    ~Settings();

public slots:

    void on_pushButton_clicked();



private slots:
    void on_listWidget_doubleClicked(const QModelIndex &index);

private:
    Ui::Settings *ui;
};

#endif // SETTINGS_H

Settings.cpp

#include "settings.h"
#include "ui_settings.h"

Settings::Settings(QWidget *parent) :
    QTabWidget(parent),
    ui(new Ui::Settings)
{
    ui->setupUi(this);
}

Settings::Settings(const Settings &s){
    stringSettings = s.stringSettings;
    doubleSettings = s.doubleSettings;
    integerSettings = s.integerSettings;
    booleanSettings = s.booleanSettings;
    longSettings = s.longSettings;
    subSettings = s.subSettings;
}


Settings::~Settings()
{
    delete ui; //Debugger pointing to this Line , when exception is thrown
}

Settings &Settings::operator =(Settings& s){
    stringSettings = s.stringSettings;
    doubleSettings = s.doubleSettings;
    integerSettings = s.integerSettings;
    booleanSettings = s.booleanSettings;
    longSettings = s.longSettings;
    subSettings = s.subSettings;
    return *this;
}

Settings* Settings::operator =(Settings *s){
    stringSettings = s->stringSettings;
    doubleSettings = s->doubleSettings;
    integerSettings = s->integerSettings;
    booleanSettings = s->booleanSettings;
    longSettings = s->longSettings;
    subSettings = s->subSettings;
    return this;
}

void Settings::on_listWidget_doubleClicked(const QModelIndex &index)
{
    Settings s = subSettings.at(index.row());
    s.show();
}

EDIT: Screenshot of debugger trace

Last line, which is executed is the destructor of Settings. As far as i can tell.

Debugger trace

c++
qt
exception
asked on Stack Overflow Nov 7, 2018 by Johannes Börnicke • edited Nov 7, 2018 by Alan Birtles

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0