App doesn't crash when attempting to open bad file through double click

This commit is contained in:
Yousef Khadadeh 2026-06-04 17:16:26 +03:00
parent 354c6e4cdc
commit 12bb936c16
5 changed files with 11 additions and 15 deletions

View file

@ -361,7 +361,6 @@ void MainProgram::set_tab_to_close(World* world) {
void MainProgram::switch_to_tab(size_t wIndex) {
world = worlds[wIndex];
worldIndex = wIndex;
}
void MainProgram::post_callback() {

View file

@ -153,7 +153,6 @@ class MainProgram {
bool drawGui = true;
size_t worldIndex = 0;
std::shared_ptr<World> world;
std::vector<std::shared_ptr<World>> worlds;

View file

@ -108,9 +108,7 @@ void DesktopDrawingProgramScreen::on_tab_close() {
main.create_new_tab({
.isClient = false
});
else if(main.world)
main.worldIndex = std::find(main.worlds.begin(), main.worlds.end(), main.world) - main.worlds.begin();
else
else if(!main.world)
main.switch_to_tab(0);
}

View file

@ -445,9 +445,11 @@ void Toolbar::top_toolbar() {
tabNames.emplace_back(w->netObjMan.is_connected() ? "data/icons/network.svg" : "", w->name + (shouldAddStarNextToName ? "*" : ""));
}
size_t worldIndex = std::find(main.worlds.begin(), main.worlds.end(), main.world) - main.worlds.begin();
gui.element<MovableTabList>("file tab list", MovableTabListData{
.tabNames = tabNames,
.selectedTab = main.worldIndex,
.selectedTab = worldIndex,
.changeSelectedTab = [&] (size_t i) {
main.switch_to_tab(i);
},

View file

@ -560,19 +560,17 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
mS.m->set_first_screen(std::make_unique<FileSelectScreen>(*mS.m));
else {
mS.m->set_first_screen(std::make_unique<DesktopDrawingProgramScreen>(*mS.m));
if(listOfFilesToOpenFromCommand.empty()) {
for(std::filesystem::path& f : listOfFilesToOpenFromCommand) {
mS.m->create_new_tab({
.isClient = false,
.filePathSource = f
});
}
if(mS.m->worlds.empty()) {
mS.m->create_new_tab({
.isClient = false
});
}
else {
for(std::filesystem::path& f : listOfFilesToOpenFromCommand) {
mS.m->create_new_tab({
.isClient = false,
.filePathSource = f
});
}
}
}
mS.m->update(); // Run update once to make sure that callbacks dont crash