diff --git a/src/node_map.cpp b/src/node_map.cpp index 9a21decd5..e8dc28110 100644 --- a/src/node_map.cpp +++ b/src/node_map.cpp @@ -102,6 +102,10 @@ NAN_METHOD(NodeMap::Load) { if (!nodeMap->isValid()) return NanThrowError(releasedMessage()); + // Reset the flag as this could be the second time + // we are calling this (being the previous successful). + nodeMap->loaded = false; + if (args.Length() < 1) { return NanThrowError("Requires a map style as first argument"); } @@ -122,6 +126,8 @@ NAN_METHOD(NodeMap::Load) { return NanThrowError(ex.what()); } + nodeMap->loaded = true; + NanReturnUndefined(); } @@ -168,6 +174,10 @@ NAN_METHOD(NodeMap::Render) { return NanThrowTypeError("Second argument must be a callback function"); } + if (!nodeMap->isLoaded()) { + return NanThrowTypeError("Style is not loaded"); + } + auto options = ParseOptions(args[0]->ToObject()); assert(!nodeMap->callback); diff --git a/src/node_map.hpp b/src/node_map.hpp index bb238ea88..d442d93bb 100644 --- a/src/node_map.hpp +++ b/src/node_map.hpp @@ -33,6 +33,8 @@ public: void renderFinished(); void release(); + + inline bool isLoaded() { return loaded; } inline bool isValid() { return valid; } static std::unique_ptr ParseOptions(v8::Local obj); @@ -60,6 +62,7 @@ private: // Async for delivering the notifications of render completion. uv_async_t *async; + bool loaded = false; bool valid = true; };