coalesce buffer deletions and run them in bulk during rendering
On iOS, the main thread does framebuffer operations just before it requests a rerender of the view contents. This means that GL operations on the Map thread will interfere with that and cause a crash. While most GL operations happen throughout rendering (which is synchronized with the main thread), deletion of shared_ptrs release in turn their OpenGL objects. This may happen at any time and isn't synced with rendering. This patch changes this so instead of deleting all objects immediately, we are collecting all abandoned IDs and delete them in bulk once the main thread has given us permission to use OpenGL calls (i.e. during render()).
This commit is contained in:
@@ -61,6 +61,7 @@ using namespace mbgl;
|
||||
|
||||
Map::Map(View& view_, FileSource& fileSource_)
|
||||
: env(util::make_unique<Environment>(fileSource_)),
|
||||
scope(util::make_unique<EnvironmentScope>(*env, ThreadType::Main, "Main")),
|
||||
view(view_),
|
||||
transform(view_),
|
||||
fileSource(fileSource_),
|
||||
@@ -80,15 +81,28 @@ Map::~Map() {
|
||||
stop();
|
||||
}
|
||||
|
||||
// Extend the scope to include both Main and Map thread types to ease cleanup.
|
||||
scope.reset();
|
||||
scope = util::make_unique<EnvironmentScope>(
|
||||
*env, static_cast<ThreadType>(static_cast<uint8_t>(ThreadType::Main) |
|
||||
static_cast<uint8_t>(ThreadType::Map)),
|
||||
"MapandMain");
|
||||
|
||||
// Explicitly reset all pointers.
|
||||
activeSources.clear();
|
||||
sprite.reset();
|
||||
glyphStore.reset();
|
||||
style.reset();
|
||||
texturePool.reset();
|
||||
workers.reset();
|
||||
painter.reset();
|
||||
annotationManager.reset();
|
||||
lineAtlas.reset();
|
||||
spriteAtlas.reset();
|
||||
glyphAtlas.reset();
|
||||
|
||||
uv_run(env->loop, UV_RUN_DEFAULT);
|
||||
|
||||
env->performCleanup();
|
||||
}
|
||||
|
||||
uv::worker &Map::getWorker() {
|
||||
@@ -113,7 +127,6 @@ void Map::start(bool startPaused) {
|
||||
|
||||
// Remove all of these to make sure they are destructed in the correct thread.
|
||||
style.reset();
|
||||
workers.reset();
|
||||
activeSources.clear();
|
||||
|
||||
terminating = true;
|
||||
@@ -233,7 +246,7 @@ void Map::run() {
|
||||
threadName += "andMain";
|
||||
}
|
||||
|
||||
Environment::Scope scope(*env, threadType, threadName);
|
||||
EnvironmentScope mapScope(*env, threadType, threadName);
|
||||
|
||||
if (mode == Mode::Continuous) {
|
||||
checkForPause();
|
||||
@@ -749,6 +762,10 @@ void Map::prepare() {
|
||||
|
||||
void Map::render() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
|
||||
// Cleanup OpenGL objects that we abandoned since the last render call.
|
||||
env->performCleanup();
|
||||
|
||||
assert(painter);
|
||||
painter->render(*style, activeSources,
|
||||
state, animationTime);
|
||||
|
||||
Reference in New Issue
Block a user