Skip to content

Commit

Permalink
Check if exceptions are even handled correctly?!?
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Aug 25, 2020
1 parent 27a32a6 commit 88227e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/aurora/2dareg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* The global 2DA registry.
*/

#include <cassert>

#include "src/common/error.h"
#include "src/common/readstream.h"

Expand Down Expand Up @@ -49,12 +51,18 @@ void TwoDARegistry::clear() {

const TwoDAFile &TwoDARegistry::get2DA(const Common::UString &name) {
TwoDAMap::const_iterator twoda = _twodas.find(name);
if (twoda != _twodas.end())
if (twoda != _twodas.end()) {
warning("FOUND \"%s\"", name.c_str());
assert(twoda->second.get() != nullptr);
// Entry exists => return
return *twoda->second;
}

warning("NOT FOUND \"%s\", load", name.c_str());
// Entry doesn't exist => load and add
return *(_twodas[name] = load2DA(name));
const TwoDAFile *new2DA = (_twodas[name] = load2DA(name)).get();
assert(new2DA != nullptr);
return *new2DA;
}

const GDAFile &TwoDARegistry::getGDA(const Common::UString &name) {
Expand Down Expand Up @@ -126,21 +134,22 @@ void TwoDARegistry::removeGDA(const Common::UString &name) {
}

std::unique_ptr<TwoDAFile> TwoDARegistry::load2DA(const Common::UString &name) {
std::unique_ptr<Common::SeekableReadStream> twodaFile;
std::unique_ptr<TwoDAFile> twoda;

try {
twodaFile.reset(ResMan.getResource(name, kFileType2DA));
std::unique_ptr<Common::SeekableReadStream> twodaFile(ResMan.getResource(name, kFileType2DA));
if (!twodaFile)
throw Common::Exception("No such 2DA");

twoda = std::make_unique<TwoDAFile>(*twodaFile);

} catch (Common::Exception &e) {
warning("NO!");
e.add("Failed loading 2DA \"%s\"", name.c_str());
throw;
}

assert(twoda.get() != nullptr);
return twoda;
}

Expand Down
3 changes: 3 additions & 0 deletions src/engines/nwn2/trap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <cassert>

#include "src/common/util.h"

#include "src/aurora/gff3file.h"
#include "src/aurora/2dafile.h"
#include "src/aurora/2dareg.h"
Expand Down Expand Up @@ -215,6 +217,7 @@ void Trap::setTrapKeyTag(const Common::UString &keyTag) {
/** Create a new trap type using the 'trapType' row data in 'traps.2da' */
void Trap::createTrapBaseType(uint8_t trapType) {
const Aurora::TwoDAFile &twoDA = TwoDAReg.get2DA("traps");
warning("GOT A two... %p", &twoDA);
const size_t count = twoDA.getRowCount();
if (trapType >= count)
return;
Expand Down

0 comments on commit 88227e4

Please sign in to comment.