diff --git a/Sources/Client/GameMap.cpp b/Sources/Client/GameMap.cpp index 91451a55..9db6bf4e 100644 --- a/Sources/Client/GameMap.cpp +++ b/Sources/Client/GameMap.cpp @@ -523,8 +523,8 @@ namespace spades { size_t len = bytes.size(); size_t pos = 0; - GameMap *map = new GameMap(); - try { + Handle map{new GameMap(), false}; + for (int y = 0; y < 512; y++) { for (int x = 0; x < 512; x++) { map->solidMap[x][y] = 0xffffffffffffffffULL; @@ -589,11 +589,7 @@ namespace spades { } } - return map; - } catch (...) { - delete map; - throw; - } + return map.Unmanage(); } } } diff --git a/Sources/Client/GameMapWrapper.cpp b/Sources/Client/GameMapWrapper.cpp index 9e39d35c..9809a45f 100644 --- a/Sources/Client/GameMapWrapper.cpp +++ b/Sources/Client/GameMapWrapper.cpp @@ -23,38 +23,35 @@ #include #include +#include "GameMap.h" +#include "GameMapWrapper.h" #include #include #include #include -#include "GameMap.h" -#include "GameMapWrapper.h" namespace spades { namespace client { - GameMapWrapper::GameMapWrapper(GameMap *mp) : map(mp) { + GameMapWrapper::GameMapWrapper(GameMap &mp) : map(mp) { SPADES_MARK_FUNCTION(); - width = mp->Width(); - height = mp->Height(); - depth = mp->Depth(); - linkMap = new uint8_t[width * height * depth]; - memset(linkMap, 0, width * height * depth); + width = mp.Width(); + height = mp.Height(); + depth = mp.Depth(); + linkMap.reset(new uint8_t[width * height * depth]); + memset(linkMap.get(), 0, width * height * depth); } - GameMapWrapper::~GameMapWrapper() { - SPADES_MARK_FUNCTION(); - delete[] linkMap; - } + GameMapWrapper::~GameMapWrapper() { SPADES_MARK_FUNCTION(); } void GameMapWrapper::Rebuild() { SPADES_MARK_FUNCTION(); Stopwatch stopwatch; - GameMap *m = map; - memset(linkMap, 0, width * height * depth); + GameMap &m = map; + memset(linkMap.get(), 0, width * height * depth); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) @@ -64,7 +61,7 @@ namespace spades { for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) - if (m->IsSolid(x, y, depth - 2)) { + if (m.IsSolid(x, y, depth - 2)) { SetLink(x, y, depth - 2, PositiveZ); queue.Push(CellPos(x, y, depth - 2)); } @@ -75,28 +72,27 @@ namespace spades { int x = p.x, y = p.y, z = p.z; - if (p.x > 0 && m->IsSolid(x - 1, y, z) && GetLink(x - 1, y, z) == Invalid) { + if (p.x > 0 && m.IsSolid(x - 1, y, z) && GetLink(x - 1, y, z) == Invalid) { SetLink(x - 1, y, z, PositiveX); queue.Push(CellPos(x - 1, y, z)); } - if (p.x < width - 1 && m->IsSolid(x + 1, y, z) && GetLink(x + 1, y, z) == Invalid) { + if (p.x < width - 1 && m.IsSolid(x + 1, y, z) && GetLink(x + 1, y, z) == Invalid) { SetLink(x + 1, y, z, NegativeX); queue.Push(CellPos(x + 1, y, z)); } - if (p.y > 0 && m->IsSolid(x, y - 1, z) && GetLink(x, y - 1, z) == Invalid) { + if (p.y > 0 && m.IsSolid(x, y - 1, z) && GetLink(x, y - 1, z) == Invalid) { SetLink(x, y - 1, z, PositiveY); queue.Push(CellPos(x, y - 1, z)); } - if (p.y < height - 1 && m->IsSolid(x, y + 1, z) && - GetLink(x, y + 1, z) == Invalid) { + if (p.y < height - 1 && m.IsSolid(x, y + 1, z) && GetLink(x, y + 1, z) == Invalid) { SetLink(x, y + 1, z, NegativeY); queue.Push(CellPos(x, y + 1, z)); } - if (p.z > 0 && m->IsSolid(x, y, z - 1) && GetLink(x, y, z - 1) == Invalid) { + if (p.z > 0 && m.IsSolid(x, y, z - 1) && GetLink(x, y, z - 1) == Invalid) { SetLink(x, y, z - 1, PositiveZ); queue.Push(CellPos(x, y, z - 1)); } - if (p.z < depth - 1 && m->IsSolid(x, y, z + 1) && GetLink(x, y, z + 1) == Invalid) { + if (p.z < depth - 1 && m.IsSolid(x, y, z + 1) && GetLink(x, y, z + 1) == Invalid) { SetLink(x, y, z + 1, NegativeZ); queue.Push(CellPos(x, y, z + 1)); } @@ -108,41 +104,41 @@ namespace spades { void GameMapWrapper::AddBlock(int x, int y, int z, uint32_t color) { SPADES_MARK_FUNCTION(); - GameMap *m = map; + GameMap &m = map; if (GetLink(x, y, z) != Invalid) { - SPAssert(m->IsSolid(x, y, z)); + SPAssert(m.IsSolid(x, y, z)); return; } - m->Set(x, y, z, true, color); + m.Set(x, y, z, true, color); if (GetLink(x, y, z) != Invalid) { return; } LinkType l = Invalid; - if (x > 0 && m->IsSolid(x - 1, y, z) && GetLink(x - 1, y, z) != Invalid) { + if (x > 0 && m.IsSolid(x - 1, y, z) && GetLink(x - 1, y, z) != Invalid) { l = NegativeX; SPAssert(GetLink(x - 1, y, z) != PositiveX); } - if (x < width - 1 && m->IsSolid(x + 1, y, z) && GetLink(x + 1, y, z) != Invalid) { + if (x < width - 1 && m.IsSolid(x + 1, y, z) && GetLink(x + 1, y, z) != Invalid) { l = PositiveX; SPAssert(GetLink(x + 1, y, z) != NegativeX); } - if (y > 0 && m->IsSolid(x, y - 1, z) && GetLink(x, y - 1, z) != Invalid) { + if (y > 0 && m.IsSolid(x, y - 1, z) && GetLink(x, y - 1, z) != Invalid) { l = NegativeY; SPAssert(GetLink(x, y - 1, z) != PositiveY); } - if (y < height - 1 && m->IsSolid(x, y + 1, z) && GetLink(x, y + 1, z) != Invalid) { + if (y < height - 1 && m.IsSolid(x, y + 1, z) && GetLink(x, y + 1, z) != Invalid) { l = PositiveY; SPAssert(GetLink(x, y + 1, z) != NegativeY); } - if (z > 0 && m->IsSolid(x, y, z - 1) && GetLink(x, y, z - 1) != Invalid) { + if (z > 0 && m.IsSolid(x, y, z - 1) && GetLink(x, y, z - 1) != Invalid) { l = NegativeZ; SPAssert(GetLink(x, y, z - 1) != PositiveZ); } - if (z < depth - 1 && m->IsSolid(x, y, z + 1) && GetLink(x, y, z + 1) != Invalid) { + if (z < depth - 1 && m.IsSolid(x, y, z + 1) && GetLink(x, y, z + 1) != Invalid) { l = PositiveZ; SPAssert(GetLink(x, y, z + 1) != NegativeZ); } @@ -159,36 +155,36 @@ namespace spades { queue.Shift(); int x = p.x, y = p.y, z = p.z; - SPAssert(m->IsSolid(x, y, z)); + SPAssert(m.IsSolid(x, y, z)); LinkType thisLink = GetLink(x, y, z); - if (p.x > 0 && m->IsSolid(x - 1, y, z) && GetLink(x - 1, y, z) == Invalid && + if (p.x > 0 && m.IsSolid(x - 1, y, z) && GetLink(x - 1, y, z) == Invalid && thisLink != NegativeX) { SetLink(x - 1, y, z, PositiveX); queue.Push(CellPos(x - 1, y, z)); } - if (p.x < width - 1 && m->IsSolid(x + 1, y, z) && GetLink(x + 1, y, z) == Invalid && + if (p.x < width - 1 && m.IsSolid(x + 1, y, z) && GetLink(x + 1, y, z) == Invalid && thisLink != PositiveX) { SetLink(x + 1, y, z, NegativeX); queue.Push(CellPos(x + 1, y, z)); } - if (p.y > 0 && m->IsSolid(x, y - 1, z) && GetLink(x, y - 1, z) == Invalid && + if (p.y > 0 && m.IsSolid(x, y - 1, z) && GetLink(x, y - 1, z) == Invalid && thisLink != NegativeY) { SetLink(x, y - 1, z, PositiveY); queue.Push(CellPos(x, y - 1, z)); } - if (p.y < height - 1 && m->IsSolid(x, y + 1, z) && - GetLink(x, y + 1, z) == Invalid && thisLink != PositiveY) { + if (p.y < height - 1 && m.IsSolid(x, y + 1, z) && GetLink(x, y + 1, z) == Invalid && + thisLink != PositiveY) { SetLink(x, y + 1, z, NegativeY); queue.Push(CellPos(x, y + 1, z)); } - if (p.z > 0 && m->IsSolid(x, y, z - 1) && GetLink(x, y, z - 1) == Invalid && + if (p.z > 0 && m.IsSolid(x, y, z - 1) && GetLink(x, y, z - 1) == Invalid && thisLink != NegativeZ) { SetLink(x, y, z - 1, PositiveZ); queue.Push(CellPos(x, y, z - 1)); } - if (p.z < depth - 1 && m->IsSolid(x, y, z + 1) && GetLink(x, y, z + 1) == Invalid && + if (p.z < depth - 1 && m.IsSolid(x, y, z + 1) && GetLink(x, y, z + 1) == Invalid && thisLink != PositiveZ) { SetLink(x, y, z + 1, NegativeZ); queue.Push(CellPos(x, y, z + 1)); @@ -206,7 +202,7 @@ namespace spades { if (cells.empty()) return std::vector(); - GameMap *m = map; + GameMap &m = map; // solid, but unlinked cells std::vector unlinkedCells; @@ -215,7 +211,7 @@ namespace spades { // unlink children for (size_t i = 0; i < cells.size(); i++) { CellPos pos = cells[i]; - m->Set(pos.x, pos.y, pos.z, false, 0); + m.Set(pos.x, pos.y, pos.z, false, 0); // if(GetLink(pos.x, pos.y, pos.z) == Invalid){ // this block is already disconnected. // } @@ -232,38 +228,38 @@ namespace spades { pos = queue.Front(); queue.Shift(); - if (m->IsSolid(pos.x, pos.y, pos.z)) + if (m.IsSolid(pos.x, pos.y, pos.z)) unlinkedCells.push_back(pos); // don't "continue;" when non-solid int x = pos.x, y = pos.y, z = pos.z; if (x > 0 && EqualTwoCond(GetLink(x - 1, y, z), PositiveX, Invalid, - m->IsSolid(x - 1, y, z))) { + m.IsSolid(x - 1, y, z))) { SetLink(x - 1, y, z, Marked); queue.Push(CellPos(x - 1, y, z)); } if (x < width - 1 && EqualTwoCond(GetLink(x + 1, y, z), NegativeX, Invalid, - m->IsSolid(x + 1, y, z))) { + m.IsSolid(x + 1, y, z))) { SetLink(x + 1, y, z, Marked); queue.Push(CellPos(x + 1, y, z)); } if (y > 0 && EqualTwoCond(GetLink(x, y - 1, z), PositiveY, Invalid, - m->IsSolid(x, y - 1, z))) { + m.IsSolid(x, y - 1, z))) { SetLink(x, y - 1, z, Marked); queue.Push(CellPos(x, y - 1, z)); } if (y < height - 1 && EqualTwoCond(GetLink(x, y + 1, z), NegativeY, Invalid, - m->IsSolid(x, y + 1, z))) { + m.IsSolid(x, y + 1, z))) { SetLink(x, y + 1, z, Marked); queue.Push(CellPos(x, y + 1, z)); } if (z > 0 && EqualTwoCond(GetLink(x, y, z - 1), PositiveZ, Invalid, - m->IsSolid(x, y, z - 1))) { + m.IsSolid(x, y, z - 1))) { SetLink(x, y, z - 1, Marked); queue.Push(CellPos(x, y, z - 1)); } if (z < depth - 1 && EqualTwoCond(GetLink(x, y, z + 1), NegativeZ, Invalid, - m->IsSolid(x, y, z + 1))) { + m.IsSolid(x, y, z + 1))) { SetLink(x, y, z + 1, Marked); queue.Push(CellPos(x, y, z + 1)); } @@ -283,7 +279,7 @@ namespace spades { for (size_t i = 0; i < unlinkedCells.size(); i++) { const CellPos &pos = unlinkedCells[i]; int x = pos.x, y = pos.y, z = pos.z; - if (!m->IsSolid(x, y, z)) { + if (!m.IsSolid(x, y, z)) { // notice: (x,y,z) may be air, so // don't use SPAssert() continue; @@ -317,32 +313,32 @@ namespace spades { int x = p.x, y = p.y, z = p.z; LinkType thisLink = GetLink(x, y, z); - if (p.x > 0 && m->IsSolid(x - 1, y, z) && GetLink(x - 1, y, z) == Invalid && + if (p.x > 0 && m.IsSolid(x - 1, y, z) && GetLink(x - 1, y, z) == Invalid && thisLink != NegativeX) { SetLink(x - 1, y, z, PositiveX); queue.Push(CellPos(x - 1, y, z)); } - if (p.x < width - 1 && m->IsSolid(x + 1, y, z) && GetLink(x + 1, y, z) == Invalid && + if (p.x < width - 1 && m.IsSolid(x + 1, y, z) && GetLink(x + 1, y, z) == Invalid && thisLink != PositiveX) { SetLink(x + 1, y, z, NegativeX); queue.Push(CellPos(x + 1, y, z)); } - if (p.y > 0 && m->IsSolid(x, y - 1, z) && GetLink(x, y - 1, z) == Invalid && + if (p.y > 0 && m.IsSolid(x, y - 1, z) && GetLink(x, y - 1, z) == Invalid && thisLink != NegativeY) { SetLink(x, y - 1, z, PositiveY); queue.Push(CellPos(x, y - 1, z)); } - if (p.y < height - 1 && m->IsSolid(x, y + 1, z) && - GetLink(x, y + 1, z) == Invalid && thisLink != PositiveY) { + if (p.y < height - 1 && m.IsSolid(x, y + 1, z) && GetLink(x, y + 1, z) == Invalid && + thisLink != PositiveY) { SetLink(x, y + 1, z, NegativeY); queue.Push(CellPos(x, y + 1, z)); } - if (p.z > 0 && m->IsSolid(x, y, z - 1) && GetLink(x, y, z - 1) == Invalid && + if (p.z > 0 && m.IsSolid(x, y, z - 1) && GetLink(x, y, z - 1) == Invalid && thisLink != NegativeZ) { SetLink(x, y, z - 1, PositiveZ); queue.Push(CellPos(x, y, z - 1)); } - if (p.z < depth - 1 && m->IsSolid(x, y, z + 1) && GetLink(x, y, z + 1) == Invalid && + if (p.z < depth - 1 && m.IsSolid(x, y, z + 1) && GetLink(x, y, z + 1) == Invalid && thisLink != PositiveZ) { SetLink(x, y, z + 1, NegativeZ); queue.Push(CellPos(x, y, z + 1)); @@ -354,7 +350,7 @@ namespace spades { for (size_t i = 0; i < unlinkedCells.size(); i++) { const CellPos &p = unlinkedCells[i]; - if (!m->IsSolid(p.x, p.y, p.z)) + if (!m.IsSolid(p.x, p.y, p.z)) continue; if (GetLink(p.x, p.y, p.z) == Invalid) { floatingBlocks.push_back(p); diff --git a/Sources/Client/GameMapWrapper.h b/Sources/Client/GameMapWrapper.h index e70ccb15..463be5c0 100644 --- a/Sources/Client/GameMapWrapper.h +++ b/Sources/Client/GameMapWrapper.h @@ -22,6 +22,7 @@ #include #include +#include namespace spades { namespace client { @@ -72,10 +73,10 @@ namespace spades { friend class Client; // FIXME: for debug public: private: - GameMap *map; + GameMap ↦ /** Each element represents where this cell is connected from. */ - uint8_t *linkMap; + std::unique_ptr linkMap; enum LinkType { Invalid = 0, @@ -100,7 +101,7 @@ namespace spades { } public: - GameMapWrapper(GameMap *); + GameMapWrapper(GameMap &); ~GameMapWrapper(); /** Addes a new block. */ diff --git a/Sources/Client/World.cpp b/Sources/Client/World.cpp index a00823f3..30c719fb 100644 --- a/Sources/Client/World.cpp +++ b/Sources/Client/World.cpp @@ -145,7 +145,7 @@ namespace spades { map = newMap; if (map) { map->AddRef(); - mapWrapper = new GameMapWrapper(map); + mapWrapper = new GameMapWrapper(*map); mapWrapper->Rebuild(); } } diff --git a/Sources/Draw/GLModelManager.cpp b/Sources/Draw/GLModelManager.cpp index cb166566..eb85f7ac 100644 --- a/Sources/Draw/GLModelManager.cpp +++ b/Sources/Draw/GLModelManager.cpp @@ -17,6 +17,7 @@ along with OpenSpades. If not, see . */ +#include #include "GLModelManager.h" #include @@ -61,24 +62,10 @@ namespace spades { GLModel *GLModelManager::CreateModel(const char *name) { SPADES_MARK_FUNCTION(); - VoxelModel *bmp; - IStream *stream = FileManager::OpenForReading(name); - try { - bmp = VoxelModel::LoadKV6(stream); - delete stream; - } catch (...) { - delete stream; - throw; - } - try { - GLModel *model = static_cast( - renderer->CreateModelOptimized(bmp)); // new GLVoxelModel(bmp, renderer); - bmp->Release(); - return model; - } catch (...) { - bmp->Release(); - throw; - } + std::unique_ptr stream{FileManager::OpenForReading(name)}; + Handle voxelModel{VoxelModel::LoadKV6(stream.get()), false}; + + return static_cast(renderer->CreateModelOptimized(voxelModel)); } } } diff --git a/Sources/Draw/SWModel.cpp b/Sources/Draw/SWModel.cpp index b76e0a27..67b89d6c 100644 --- a/Sources/Draw/SWModel.cpp +++ b/Sources/Draw/SWModel.cpp @@ -118,20 +118,18 @@ namespace spades { SWModel *SWModelManager::RegisterModel(const std::string &name) { auto it = models.find(name); if (it == models.end()) { - auto *str = FileManager::OpenForReading(name.c_str()); + std::unique_ptr stream{FileManager::OpenForReading(name.c_str())}; + Handle vm; - try { - vm.Set(VoxelModel::LoadKV6(str), false); - auto *m = CreateModel(vm); - models.insert(std::make_pair(name, m)); - m->AddRef(); - return m; - } catch (...) { - delete str; - throw; - } + vm.Set(VoxelModel::LoadKV6(stream.get()), false); + + SWModel *model = CreateModel(vm); + models.insert(std::make_pair(name, model)); + model->AddRef(); + + return model; } else { - auto *model = it->second; + SWModel *model = it->second; model->AddRef(); return model; } diff --git a/Sources/Gui/MainScreenHelper.cpp b/Sources/Gui/MainScreenHelper.cpp index db555bea..8393c5f8 100644 --- a/Sources/Gui/MainScreenHelper.cpp +++ b/Sources/Gui/MainScreenHelper.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -119,34 +120,29 @@ namespace spades { return size; } - void ReturnResult(MainScreenServerList *list) { + void ReturnResult(std::unique_ptr list) { AutoLocker lock(&(owner->newResultArrayLock)); - delete owner->newResult; - owner->newResult = list; + owner->newResult = std::move(list); owner = NULL; // release owner } void ProcessResponse() { Json::Reader reader; Json::Value root; - MainScreenServerList *resp = new MainScreenServerList(); - try { + std::unique_ptr resp{new MainScreenServerList()}; + if (reader.parse(buffer, root, false)) { for (Json::Value::iterator it = root.begin(); it != root.end(); ++it) { Json::Value &obj = *it; - Serveritem *srv = Serveritem::create(obj); + std::unique_ptr srv{Serveritem::create(obj)}; if (srv) { resp->list.push_back(new MainScreenServerItem( - srv, owner->favorites.count(srv->Ip()) >= 1)); - delete srv; + srv.get(), owner->favorites.count(srv->Ip()) >= 1)); } } } - ReturnResult(resp); - } catch (...) { - delete resp; - throw; - } + + ReturnResult(std::move(resp)); } public: @@ -178,19 +174,19 @@ namespace spades { SPRaise("Failed to create cURL object."); } } catch (std::exception &ex) { - MainScreenServerList *lst = new MainScreenServerList(); + std::unique_ptr lst{new MainScreenServerList()}; lst->message = ex.what(); - ReturnResult(lst); + ReturnResult(std::move(lst)); } catch (...) { - MainScreenServerList *lst = new MainScreenServerList(); + std::unique_ptr lst{new MainScreenServerList()}; lst->message = "Unknown error."; - ReturnResult(lst); + ReturnResult(std::move(lst)); } } }; MainScreenHelper::MainScreenHelper(MainScreen *scr) - : mainScreen(scr), result(NULL), newResult(NULL), query(NULL) { + : mainScreen(scr), query(NULL) { SPADES_MARK_FUNCTION(); LoadFavorites(); } @@ -200,8 +196,6 @@ namespace spades { if (query) { query->MarkForAutoDeletion(); } - delete result; - delete newResult; } void MainScreenHelper::MainScreenDestroyed() { @@ -261,9 +255,9 @@ namespace spades { SPADES_MARK_FUNCTION(); AutoLocker lock(&newResultArrayLock); if (newResult) { - delete result; - result = newResult; - newResult = NULL; + // Move `newResult` to `result` + result = std::move(newResult); + SPAssert(!newResult); query->MarkForAutoDeletion(); query = NULL; return true; diff --git a/Sources/Gui/MainScreenHelper.h b/Sources/Gui/MainScreenHelper.h index 27ec6963..1b647361 100644 --- a/Sources/Gui/MainScreenHelper.h +++ b/Sources/Gui/MainScreenHelper.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -78,8 +79,8 @@ namespace spades { class ServerListQuery; MainScreen *mainScreen; - MainScreenServerList *result; - MainScreenServerList *newResult; + std::unique_ptr result; + std::unique_ptr newResult; Mutex newResultArrayLock; ServerListQuery *query; std::string errorMessage; diff --git a/Sources/ScriptBindings/Bitmap.cpp b/Sources/ScriptBindings/Bitmap.cpp index 2e8a3277..62edde5e 100644 --- a/Sources/ScriptBindings/Bitmap.cpp +++ b/Sources/ScriptBindings/Bitmap.cpp @@ -32,7 +32,7 @@ namespace spades { return Bitmap::Load(str); }catch(const std::exception& ex) { ScriptContextUtils().SetNativeException(ex); - return NULL; + return nullptr; } } diff --git a/Sources/ScriptBindings/GameMap.cpp b/Sources/ScriptBindings/GameMap.cpp index 9f276dcf..707d414f 100644 --- a/Sources/ScriptBindings/GameMap.cpp +++ b/Sources/ScriptBindings/GameMap.cpp @@ -17,7 +17,7 @@ along with OpenSpades. If not, see . */ - +#include #include #include "ScriptManager.h" #include @@ -32,26 +32,23 @@ namespace spades { h != GameMap::DefaultHeight || d != GameMap::DefaultDepth) { asGetActiveContext()->SetException("Currently, non-default GameMap dimensions aren't supported."); - return NULL; + return nullptr; } try{ return new GameMap(); }catch(const std::exception& ex){ ScriptContextUtils().SetNativeException(ex); - return NULL; + return nullptr; } } static GameMap *LoadFactory(const std::string& fn){ - spades::IStream *stream = NULL; try{ - stream = FileManager::OpenForReading(fn.c_str()); - GameMap *ret = GameMap::Load(stream); - delete stream; + std::unique_ptr stream{FileManager::OpenForReading(fn.c_str())}; + GameMap *ret = GameMap::Load(stream.get()); return ret; }catch(const std::exception& ex) { ScriptContextUtils().SetNativeException(ex); - if(stream) delete stream; - return NULL; + return nullptr; } } diff --git a/Sources/ScriptBindings/IAudioDevice.cpp b/Sources/ScriptBindings/IAudioDevice.cpp index ca5f1bd1..4fc09a55 100644 --- a/Sources/ScriptBindings/IAudioDevice.cpp +++ b/Sources/ScriptBindings/IAudioDevice.cpp @@ -38,7 +38,7 @@ namespace spades { return c; }catch(const std::exception& ex) { ScriptContextUtils().SetNativeException(ex); - return NULL; + return nullptr; } } public: diff --git a/Sources/ScriptBindings/IRenderer.cpp b/Sources/ScriptBindings/IRenderer.cpp index e164f2c3..cdccec23 100644 --- a/Sources/ScriptBindings/IRenderer.cpp +++ b/Sources/ScriptBindings/IRenderer.cpp @@ -47,7 +47,7 @@ namespace spades { return im; }catch(const std::exception& ex) { ScriptContextUtils().SetNativeException(ex); - return NULL; + return nullptr; } } static void AddDebugLine(const Vector3& a, const Vector3& b, diff --git a/Sources/ScriptBindings/VoxelModel.cpp b/Sources/ScriptBindings/VoxelModel.cpp index a8a3cc1c..4e3a1389 100644 --- a/Sources/ScriptBindings/VoxelModel.cpp +++ b/Sources/ScriptBindings/VoxelModel.cpp @@ -17,7 +17,7 @@ along with OpenSpades. If not, see . */ - +#include #include #include "ScriptManager.h" #include @@ -31,20 +31,17 @@ namespace spades { return new VoxelModel(w, h, d); }catch(const std::exception& ex){ ScriptContextUtils().SetNativeException(ex); - return NULL; + return nullptr; } } static VoxelModel *LoadFactory(const std::string& fn){ - spades::IStream *stream = NULL; try{ - stream = FileManager::OpenForReading(fn.c_str()); - VoxelModel *ret = VoxelModel::LoadKV6(stream); - delete stream; + std::unique_ptr stream{FileManager::OpenForReading(fn.c_str())}; + VoxelModel *ret = VoxelModel::LoadKV6(stream.get()); return ret; }catch(const std::exception& ex) { ScriptContextUtils().SetNativeException(ex); - if(stream) delete stream; - return NULL; + return nullptr; } } static uint64_t GetSolidBits(int x, int y,