fix crash in main menu

This commit is contained in:
Skarn
2020-11-04 14:50:49 +03:00
parent 09a0eff7e5
commit 10fffc092e
5 changed files with 35 additions and 16 deletions

View File

@@ -203,11 +203,12 @@ MapCreationWizard::MapCreationWizard(QWidget* parent) : noggit::ui::widget(paren
});
connect(reinterpret_cast<noggit::ui::main_window*>(parent), QOverload<int>::of(&noggit::ui::main_window::map_selected)
, [&] (int index)
{
selectMap(index);
}
_connection = connect(reinterpret_cast<noggit::ui::main_window*>(parent),
QOverload<int>::of(&noggit::ui::main_window::map_selected)
, [&] (int index)
{
selectMap(index);
}
);
// Selection
@@ -269,8 +270,13 @@ void MapCreationWizard::selectMap(int map_id)
DBCFile::Record record = gMapDB.getByID(map_id);
_cur_map_id = map_id;
_world = std::make_unique<World>(record.getString(MapDB::InternalName), map_id);
_minimap_widget->world(_world.get());
if (_world)
{
delete _world;
}
_world = new World(record.getString(MapDB::InternalName), map_id);
_minimap_widget->world(_world);
_directory->setText(record.getString(1));
_instance_type->setCurrentIndex(record.getInt(2));
@@ -330,7 +336,7 @@ void MapCreationWizard::wheelEvent(QWheelEvent* event)
void MapCreationWizard::saveCurrentEntry()
{
// Save ADTs to disk
_world->mapIndex.saveChanged(_world.get(), true);
_world->mapIndex.saveChanged(_world, true);
_world->mapIndex.save();
// Save Map.dbc record
@@ -362,6 +368,12 @@ void MapCreationWizard::discardChanges()
}
MapCreationWizard::~MapCreationWizard()
{
delete _world;
disconnect(_connection);
}
LocaleDBCEntry::LocaleDBCEntry(QWidget* parent) : QWidget(parent)
{

View File

@@ -20,8 +20,8 @@
#include <noggit/ui/minimap_widget.hpp>
#include <noggit/ui/widget.hpp>
#include <noggit/World.h>
class World;
namespace noggit
{
@@ -78,7 +78,10 @@ namespace noggit
{
public:
MapCreationWizard(QWidget *parent = nullptr);
~MapCreationWizard();
void wheelEvent(QWheelEvent *event) override;
void destroyFakeWorld() { if(_world) delete _world; _world = nullptr; _minimap_widget->world (nullptr); };
private:
ui::minimap_widget* _minimap_widget;
@@ -108,11 +111,13 @@ namespace noggit
QSpinBox* _raid_offset;
QSpinBox* _max_players;
std::unique_ptr<World> _world;
World* _world = nullptr;
bool _is_new_record = false;
int _cur_map_id = 0;
QMetaObject::Connection _connection;
void selectMap(int map_id);
void saveCurrentEntry();

View File

@@ -141,6 +141,8 @@ namespace noggit
, bool from_bookmark
)
{
_map_creation_wizard->destroyFakeWorld();
delete _map_creation_wizard;
auto mapview (new MapView (camera_yaw, camera_pitch, pos, this, std::move (_world), uid_fix, from_bookmark));
connect(mapview, &MapView::uid_fix_failed, [this]() { prompt_uid_fix_failure(); });
@@ -151,8 +153,6 @@ namespace noggit
void main_window::loadMap(int mapID)
{
emit map_selected(mapID);
_minimap->world (nullptr);
_world.reset();
@@ -163,6 +163,7 @@ namespace noggit
{
_world = std::make_unique<World> (it->getString(MapDB::InternalName), mapID);
_minimap->world (_world.get());
emit map_selected(mapID);
return;
}
@@ -276,14 +277,13 @@ namespace noggit
minimap_holder_layout->setAlignment(Qt::AlignCenter);
right_side->addTab(minimap_holder, "Enter map");
auto map_creation_wizard = new noggit::Red::MapCreationWizard::Ui::MapCreationWizard(this);
right_side->addTab(map_creation_wizard, "Edit map");
_map_creation_wizard = new noggit::Red::MapCreationWizard::Ui::MapCreationWizard(this);
right_side->addTab(_map_creation_wizard, "Edit map");
layout->addWidget(right_side);
setCentralWidget (widget);
_minimap->adjustSize();
}

View File

@@ -4,6 +4,7 @@
#include <math/trig.hpp>
#include <noggit/World.h>
#include <noggit/ui/uid_fix_window.hpp>
#include <noggit/Red/MapCreationWizard/UI/MapCreationWizard.hpp>
#include <QtWidgets/QMainWindow>
@@ -77,6 +78,7 @@ namespace noggit
settings* _settings;
about* _about;
QWidget* _null_widget;
noggit::Red::MapCreationWizard::Ui::MapCreationWizard* _map_creation_wizard;
std::unique_ptr<World> _world;

View File

@@ -61,7 +61,7 @@ namespace noggit
void reset_selection();
private:
World const* _world;
World* _world;
noggit::camera* _camera;
std::array<bool, 4096>* _selected_tiles;