Cancel pending Style requests before making a new one
Calling setStyleURL() multiple times in a short period of time will enqueue requests on the FileSource. The order they get replied is not guaranteed to be the same as the order we make the requests. The side effect was the last style set not always being the one rendered. Now we cancel the current request if we make a new one (and there was no point on keeping it around anyway).
This commit is contained in:
@@ -50,6 +50,12 @@ MapContext::~MapContext() {
|
||||
void MapContext::cleanup() {
|
||||
view.notify();
|
||||
|
||||
if (styleRequest) {
|
||||
FileSource* fs = util::ThreadContext::getFileSource();
|
||||
fs->cancel(styleRequest);
|
||||
styleRequest = nullptr;
|
||||
}
|
||||
|
||||
// Explicit resets currently necessary because these abandon resources that need to be
|
||||
// cleaned up by glObjectStore.performCleanup();
|
||||
style.reset();
|
||||
@@ -85,6 +91,12 @@ void MapContext::triggerUpdate(const TransformState& state, const Update u) {
|
||||
}
|
||||
|
||||
void MapContext::setStyleURL(const std::string& url) {
|
||||
FileSource* fs = util::ThreadContext::getFileSource();
|
||||
|
||||
if (styleRequest) {
|
||||
fs->cancel(styleRequest);
|
||||
}
|
||||
|
||||
styleURL = url;
|
||||
styleJSON.clear();
|
||||
|
||||
@@ -94,8 +106,9 @@ void MapContext::setStyleURL(const std::string& url) {
|
||||
base = styleURL.substr(0, pos + 1);
|
||||
}
|
||||
|
||||
FileSource* fs = util::ThreadContext::getFileSource();
|
||||
fs->request({ Resource::Kind::Style, styleURL }, util::RunLoop::current.get()->get(), [this, base](const Response &res) {
|
||||
styleRequest = fs->request({ Resource::Kind::Style, styleURL }, util::RunLoop::current.get()->get(), [this, base](const Response &res) {
|
||||
styleRequest = nullptr;
|
||||
|
||||
if (res.status == Response::Successful) {
|
||||
loadStyleJSON(res.data, base);
|
||||
} else {
|
||||
|
||||
@@ -92,6 +92,8 @@ private:
|
||||
std::string styleURL;
|
||||
std::string styleJSON;
|
||||
|
||||
Request* styleRequest = nullptr;
|
||||
|
||||
StillImageCallback callback;
|
||||
size_t sourceCacheSize;
|
||||
TransformState transformState;
|
||||
|
||||
Reference in New Issue
Block a user