Skip to content

Commit

Permalink
Fix CTD if user zooms after chart doesn't load
Browse files Browse the repository at this point in the history
  • Loading branch information
fpw committed May 14, 2023
1 parent 7ade376 commit cff4c23
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.9)
project(AviTab VERSION 0.6.2 DESCRIPTION "AviTab X-Plane plugin")
project(AviTab VERSION 0.6.3 DESCRIPTION "AviTab X-Plane plugin")

if (NOT "$ENV{NAVIGRAPH_SECRET}" STREQUAL "")
set(NAVIGRAPH_SECRET "$ENV{NAVIGRAPH_SECRET}" CACHE INTERNAL "Copied from environment variable")
Expand Down
87 changes: 51 additions & 36 deletions src/avitab/apps/AirportApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,65 +382,80 @@ void AirportApp::onChartsLoaded(std::shared_ptr<Page> page, const apis::ChartSer
void AirportApp::onChartLoaded(std::shared_ptr<Page> page) {
TabPage &tab = findPage(page);

tab.label->setVisible(false);
if (api().getSettings()->getGeneralSetting<bool>("show_overlays_in_airport_app")) {
tab.overlays = api().getSettings()->getOverlayConfig();
} else {
tab.overlays = std::make_shared<maps::OverlayConfig>();
}
tab.window->addSymbol(Widget::Symbol::MINUS, [this, page] {
TabPage &tab = findPage(page);
tab.map->zoomOut();
if (tab.map) {
tab.map->zoomOut();
}
});
tab.window->addSymbol(Widget::Symbol::PLUS, [this, page] {
TabPage &tab = findPage(page);
tab.map->zoomIn();
if (tab.map) {
tab.map->zoomIn();
}
});
tab.window->addSymbol(Widget::Symbol::ROTATE, [this, page] {
TabPage &tab = findPage(page);
tab.mapStitcher->rotateRight();
if (tab.map) {
tab.mapStitcher->rotateRight();
}
});
tab.nightModeButton = tab.window->addSymbol(Widget::Symbol::IMAGE, [this, page] () {
TabPage &tab = findPage(page);
nightMode = !nightMode;
tab.nightModeButton->setToggleState(nightMode);
tab.chart->changeNightMode(tab.mapSource, nightMode);
tab.mapStitcher->invalidateCache();
if (tab.map) {
nightMode = !nightMode;
tab.nightModeButton->setToggleState(nightMode);
tab.chart->changeNightMode(tab.mapSource, nightMode);
tab.mapStitcher->invalidateCache();
}
});
tab.nightModeButton->setToggleState(nightMode);
tab.aircraftButton = tab.window->addSymbol(Widget::Symbol::GPS, [this, page] {
TabPage &tab = findPage(page);
tab.overlays->drawMyAircraft = !tab.overlays->drawMyAircraft;
tab.aircraftButton->setToggleState(tab.overlays->drawMyAircraft);
if (tab.map) {
tab.overlays->drawMyAircraft = !tab.overlays->drawMyAircraft;
tab.aircraftButton->setToggleState(tab.overlays->drawMyAircraft);
}
});

tab.mapImage = std::make_shared<img::Image>(tab.window->getContentWidth(), tab.window->getHeight(), 0);
tab.pixMap = std::make_shared<PixMap>(tab.window);
tab.pixMap->draw(*tab.mapImage);
tab.pixMap->setClickable(true);
tab.pixMap->setClickHandler([this, page] (int x, int y, bool pr, bool rel) { onMapPan(page, x, y, pr, rel); });
tab.pixMap->setDimensions(tab.window->getContentWidth(), tab.window->getHeight() - padHeight);
tab.pixMap->centerInParent();

tab.mapSource = tab.chart->createTileSource(nightMode);
tab.mapStitcher = std::make_shared<img::Stitcher>(tab.mapImage, tab.mapSource);
tab.map = std::make_shared<maps::OverlayedMap>(tab.mapStitcher, tab.overlays);
tab.map->loadOverlayIcons(api().getDataPath() + "icons/");
tab.map->setRedrawCallback([this, page] () { redrawPage(page); });
tab.map->setNavWorld(api().getNavWorld());

tab.aircraftButton->setToggleState(tab.map->getOverlayConfig().drawMyAircraft);

if (tab.mapSource->getPageCount() > 1) {
tab.window->addSymbol(Widget::Symbol::RIGHT, [this, page] {
TabPage &tab = findPage(page);
tab.mapStitcher->nextPage();
});
try {
tab.mapImage = std::make_shared<img::Image>(tab.window->getContentWidth(), tab.window->getHeight(), 0);
tab.pixMap = std::make_shared<PixMap>(tab.window);
tab.pixMap->draw(*tab.mapImage);
tab.pixMap->setClickable(true);
tab.pixMap->setClickHandler([this, page] (int x, int y, bool pr, bool rel) { onMapPan(page, x, y, pr, rel); });
tab.pixMap->setDimensions(tab.window->getContentWidth(), tab.window->getHeight() - padHeight);
tab.pixMap->centerInParent();

tab.mapSource = tab.chart->createTileSource(nightMode);
tab.mapStitcher = std::make_shared<img::Stitcher>(tab.mapImage, tab.mapSource);
tab.map = std::make_shared<maps::OverlayedMap>(tab.mapStitcher, tab.overlays);
tab.map->loadOverlayIcons(api().getDataPath() + "icons/");
tab.map->setRedrawCallback([this, page] () { redrawPage(page); });
tab.map->setNavWorld(api().getNavWorld());

tab.aircraftButton->setToggleState(tab.map->getOverlayConfig().drawMyAircraft);

if (tab.mapSource->getPageCount() > 1) {
tab.window->addSymbol(Widget::Symbol::RIGHT, [this, page] {
TabPage &tab = findPage(page);
tab.mapStitcher->nextPage();
});

tab.window->addSymbol(Widget::Symbol::LEFT, [this, page] {
TabPage &tab = findPage(page);
tab.mapStitcher->prevPage();
});
tab.window->addSymbol(Widget::Symbol::LEFT, [this, page] {
TabPage &tab = findPage(page);
tab.mapStitcher->prevPage();
});
}
tab.label->setVisible(false);
} catch (const std::exception &e) {
logger::warn("Couldn't load chart: %s", e.what());
tab.label->setText(e.what());
}

onTimer();
Expand Down

0 comments on commit cff4c23

Please sign in to comment.