Move loading of data error handling

This commit is contained in:
Malin E
2022-08-29 13:13:47 +02:00
parent 53b2d0e76c
commit dc55105000
3 changed files with 18 additions and 7 deletions

View File

@@ -81,7 +81,7 @@ RenderableConstellationBounds::RenderableConstellationBounds(
// Avoid reading files here, instead do it in multithreaded initialize()
_vertexFilename = absPath(p.file.string()).string();
_vertexFilename.onChange([&](){ loadVertexFile(); });
_vertexFilename.onChange([&](){ loadData(); });
addProperty(_vertexFilename);
_color.setViewOption(properties::Property::ViewOptions::Color);
@@ -92,7 +92,7 @@ RenderableConstellationBounds::RenderableConstellationBounds(
void RenderableConstellationBounds::initialize() {
RenderableConstellationsBase::initialize();
loadVertexFile();
loadData();
if (!_assetSelection.empty()) {
const std::vector<std::string> options = _selection.options();
@@ -198,6 +198,14 @@ void RenderableConstellationBounds::render(const RenderData& data, RendererTasks
void RenderableConstellationBounds::update(const UpdateData& data) { }
bool RenderableConstellationBounds::loadData() {
bool success = loadVertexFile();
if (!success) {
throw ghoul::RuntimeError("Error loading data");
}
return success;
}
bool RenderableConstellationBounds::loadVertexFile() {
if (_vertexFilename.value().empty()) {
return false;

View File

@@ -75,6 +75,7 @@ private:
* \return \c true if the loading succeeded, \c false otherwise
*/
bool loadVertexFile();
bool loadData();
/**
* Callback method that gets triggered when <code>_constellationSelection</code>

View File

@@ -101,6 +101,7 @@ RenderableConstellationLines::RenderableConstellationLines(
const Parameters p = codegen::bake<Parameters>(dictionary);
_speckFile = absPath(p.file);
addProperty(_drawElements);
if (p.lineUnit.has_value()) {
@@ -150,10 +151,7 @@ bool RenderableConstellationLines::isReady() const {
void RenderableConstellationLines::initialize() {
RenderableConstellationsBase::initialize();
bool success = loadData();
if (!success) {
throw ghoul::RuntimeError("Error loading data");
}
loadData();
if (!_assetSelection.empty()) {
const std::vector<std::string> options = _selection.options();
@@ -268,7 +266,11 @@ void RenderableConstellationLines::update(const UpdateData&) {
}
bool RenderableConstellationLines::loadData() {
return readSpeckFile();
bool success = readSpeckFile();
if (!success) {
throw ghoul::RuntimeError("Error loading data");
}
return success;
}
bool RenderableConstellationLines::readSpeckFile() {