From 9534d6256b370740b59102630dfb517399ca0fc7 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 11 Aug 2015 09:06:19 +1000 Subject: [PATCH] Fix ThreadContext to check for valid current pointer --- src/mbgl/util/thread_context.hpp | 36 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/mbgl/util/thread_context.hpp b/src/mbgl/util/thread_context.hpp index a2be0cd364f..626925bdcdc 100644 --- a/src/mbgl/util/thread_context.hpp +++ b/src/mbgl/util/thread_context.hpp @@ -36,27 +36,51 @@ struct ThreadContext { } static std::string getName() { - return current.get()->name; + if (current.get() != nullptr) { + return current.get()->name; + } else { + return "Unknown"; + } } static ThreadPriority getPriority() { - return current.get()->priority; + if (current.get() != nullptr) { + return current.get()->priority; + } else { + return ThreadPriority::Regular; + } } static FileSource* getFileSource() { - return current.get()->fileSource; + if (current.get() != nullptr) { + return current.get()->fileSource; + } else { + return nullptr; + } } static void setFileSource(FileSource* fileSource) { - current.get()->fileSource = fileSource; + if (current.get() != nullptr) { + current.get()->fileSource = fileSource; + } else { + throw new std::runtime_error("Current thread has no current ThreadContext."); + } } static GLObjectStore* getGLObjectStore() { - return current.get()->glObjectStore; + if (current.get() != nullptr) { + return current.get()->glObjectStore; + } else { + return nullptr; + } } static void setGLObjectStore(GLObjectStore* glObjectStore) { - current.get()->glObjectStore = glObjectStore; + if (current.get() != nullptr) { + current.get()->glObjectStore = glObjectStore; + } else { + throw new std::runtime_error("Current thread has no current ThreadContext."); + } } private: