From 16fd5312183e3c064f2d51507a6feb5fb1af45d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20C=C3=A9r=C3=A8s?= Date: Thu, 24 Mar 2016 14:47:09 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Correction=20d'une=20fuite=20m=C3=A9moire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resource_manager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/resource_manager.cpp b/src/resource_manager.cpp index 9fde703..4803e47 100644 --- a/src/resource_manager.cpp +++ b/src/resource_manager.cpp @@ -18,15 +18,15 @@ ResourceManager::~ResourceManager() { */ std::string getCurrentDirectory() { int length = wai_getExecutablePath(NULL, 0, NULL), dirname_length; - char* buffer = new char[length + 1]; - wai_getExecutablePath(buffer, length, &dirname_length); + std::unique_ptr buffer = std::unique_ptr(new char[length + 1]); + wai_getExecutablePath(buffer.get(), length, &dirname_length); if (dirname_length == 0) { throw std::runtime_error("Impossible de déterminer le chemin actuel"); } - buffer[length] = '\0'; - return std::string(buffer).substr(0, dirname_length); + buffer.get()[length] = '\0'; + return std::string(buffer.get()).substr(0, dirname_length); } sf::Texture& ResourceManager::getTexture(std::string name) { From 586ba7ca106898fe2ea5d9e03d43605356424dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20C=C3=A9r=C3=A8s?= Date: Thu, 24 Mar 2016 17:20:13 +0100 Subject: [PATCH 2/3] Correction de l'inclusion --- src/resource_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/resource_manager.cpp b/src/resource_manager.cpp index 4803e47..a418aea 100644 --- a/src/resource_manager.cpp +++ b/src/resource_manager.cpp @@ -1,6 +1,7 @@ #include "resource_manager.hpp" #include "whereami.h" #include +#include #ifdef _WIN32 #define FILE_SEP '\\' From fbc43a400beb138f2ba6a26a2cc74c20a5cdf893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Thu, 24 Mar 2016 20:11:25 +0100 Subject: [PATCH 3/3] Prise en charge propre des exceptions --- src/main.cpp | 13 +++++++++++-- src/resource_manager.cpp | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1c0f6b1..f3dc232 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "block.hpp" #include "engine.hpp" #include "constants.hpp" +#include #include int main() { @@ -62,6 +63,14 @@ int main() { engine.addObject(block21); engine.addObject(block22); - engine.start(); - return 0; + try { + engine.start(); + } catch (const std::exception& exception) { + std::cerr << std::endl; + std::cerr << "Le programme a quitté après une erreur d'exécution." << std::endl; + std::cerr << exception.what() << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; } diff --git a/src/resource_manager.cpp b/src/resource_manager.cpp index a418aea..31da7ec 100644 --- a/src/resource_manager.cpp +++ b/src/resource_manager.cpp @@ -41,7 +41,7 @@ sf::Texture& ResourceManager::getTexture(std::string name) { // tente de charger la texture dans le chemin "CWD/res/name" if (!texture.loadFromFile(path)) { - throw std::runtime_error("Impossible de charger l'image: " + name); + throw std::runtime_error("Impossible de charger l'image : " + name); } textures[name] = texture;