forked from organicmaps/organicmaps-tmp
Fixed crash on drape initialization in background
This commit is contained in:
parent
f1a5f885c5
commit
f8cbf10eea
11 changed files with 52 additions and 43 deletions
|
@ -41,4 +41,9 @@ OGLContext * ThreadSafeFactory::CreateContext(TCreateCtxFn const & createFn, TIs
|
|||
return ctx;
|
||||
}
|
||||
|
||||
void ThreadSafeFactory::waitForInitialization()
|
||||
{
|
||||
m_factory->waitForInitialization();
|
||||
}
|
||||
|
||||
} // namespace dp
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
virtual OGLContext * getResourcesUploadContext() = 0;
|
||||
virtual bool isDrawContextCreated() const { return false; }
|
||||
virtual bool isUploadContextCreated() const { return false; }
|
||||
virtual void waitForInitialization() {}
|
||||
};
|
||||
|
||||
class ThreadSafeFactory : public OGLContextFactory
|
||||
|
@ -25,8 +26,8 @@ class ThreadSafeFactory : public OGLContextFactory
|
|||
public:
|
||||
ThreadSafeFactory(OGLContextFactory * factory, bool enableSharing = true);
|
||||
~ThreadSafeFactory();
|
||||
virtual OGLContext * getDrawContext();
|
||||
virtual OGLContext * getResourcesUploadContext();
|
||||
OGLContext * getDrawContext() override;
|
||||
OGLContext * getResourcesUploadContext() override;
|
||||
|
||||
template<typename T>
|
||||
T * CastFactory()
|
||||
|
@ -35,6 +36,8 @@ public:
|
|||
return static_cast<T *>(m_factory);
|
||||
}
|
||||
|
||||
void waitForInitialization() override;
|
||||
|
||||
protected:
|
||||
typedef function<OGLContext * ()> TCreateCtxFn;
|
||||
typedef function<bool()> TIsSeparateCreatedFn;
|
||||
|
|
|
@ -255,11 +255,6 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
MessagePriority::Normal);
|
||||
break;
|
||||
}
|
||||
case Message::StopRendering:
|
||||
{
|
||||
ProcessStopRenderingMessage();
|
||||
break;
|
||||
}
|
||||
case Message::Allow3dBuildings:
|
||||
{
|
||||
ref_ptr<Allow3dBuildingsMessage> msg = message;
|
||||
|
@ -288,6 +283,8 @@ BackendRenderer::Routine::Routine(BackendRenderer & renderer) : m_renderer(rende
|
|||
|
||||
void BackendRenderer::Routine::Do()
|
||||
{
|
||||
m_renderer.m_contextFactory->waitForInitialization();
|
||||
|
||||
m_renderer.m_contextFactory->getResourcesUploadContext()->makeCurrent();
|
||||
GLFunctions::Init();
|
||||
|
||||
|
|
|
@ -25,10 +25,9 @@ void BaseRenderer::StartThread()
|
|||
|
||||
void BaseRenderer::StopThread()
|
||||
{
|
||||
// send message to stop rendering in render thread
|
||||
m_commutator->PostMessage(m_threadName,
|
||||
make_unique_dp<StopRenderingMessage>(),
|
||||
MessagePriority::High);
|
||||
// stop rendering and close queue
|
||||
m_selfThread.GetRoutine()->Cancel();
|
||||
CloseQueue();
|
||||
|
||||
// wake up render thread if necessary
|
||||
if (!m_isEnabled)
|
||||
|
@ -134,12 +133,6 @@ void BaseRenderer::WakeUp()
|
|||
m_renderingEnablingCondition.notify_one();
|
||||
}
|
||||
|
||||
void BaseRenderer::ProcessStopRenderingMessage()
|
||||
{
|
||||
m_selfThread.GetRoutine()->Cancel();
|
||||
CloseQueue();
|
||||
}
|
||||
|
||||
bool BaseRenderer::CanReceiveMessages()
|
||||
{
|
||||
threads::IRoutine * routine = m_selfThread.GetRoutine();
|
||||
|
|
|
@ -52,7 +52,6 @@ protected:
|
|||
void StopThread();
|
||||
|
||||
void CheckRenderingEnabled();
|
||||
void ProcessStopRenderingMessage();
|
||||
|
||||
virtual unique_ptr<threads::IRoutine> CreateRoutine() = 0;
|
||||
|
||||
|
|
|
@ -356,12 +356,6 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
break;
|
||||
}
|
||||
|
||||
case Message::StopRendering:
|
||||
{
|
||||
ProcessStopRenderingMessage();
|
||||
break;
|
||||
}
|
||||
|
||||
case Message::MyPositionShape:
|
||||
{
|
||||
ref_ptr<MyPositionShapeMessage> msg = message;
|
||||
|
@ -1388,6 +1382,8 @@ FrontendRenderer::Routine::Routine(FrontendRenderer & renderer) : m_renderer(ren
|
|||
|
||||
void FrontendRenderer::Routine::Do()
|
||||
{
|
||||
m_renderer.m_contextFactory->waitForInitialization();
|
||||
|
||||
gui::DrapeGui::Instance().ConnectOnCompassTappedHandler(bind(&FrontendRenderer::OnCompassTapped, &m_renderer));
|
||||
m_renderer.m_myPositionController->SetListener(ref_ptr<MyPositionController::Listener>(&m_renderer));
|
||||
m_renderer.m_userEventStream.SetListener(ref_ptr<UserEventStream::Listener>(&m_renderer));
|
||||
|
|
|
@ -27,7 +27,6 @@ public:
|
|||
GuiRecache,
|
||||
GuiLayerLayout,
|
||||
MyPositionShape,
|
||||
StopRendering,
|
||||
ChangeMyPostitionMode,
|
||||
CompassInfo,
|
||||
GpsInfo,
|
||||
|
|
|
@ -366,13 +366,6 @@ private:
|
|||
drape_ptr<SelectionShape> m_selection;
|
||||
};
|
||||
|
||||
class StopRenderingMessage : public Message
|
||||
{
|
||||
public:
|
||||
StopRenderingMessage(){}
|
||||
Type GetType() const override { return Message::StopRendering; }
|
||||
};
|
||||
|
||||
class ChangeMyPositionModeMessage : public Message
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -89,7 +89,7 @@ double getExactDPI(double contentScaleFactor)
|
|||
|
||||
- (void)createDrapeEngineWithWidth:(int)width height:(int)height
|
||||
{
|
||||
NSLog(@"EAGLView createDrapeEngine Started");
|
||||
LOG(LINFO, ("EAGLView createDrapeEngine Started"));
|
||||
if (MapsAppDelegate.theApp.isDaemonMode)
|
||||
return;
|
||||
|
||||
|
@ -103,7 +103,7 @@ double getExactDPI(double contentScaleFactor)
|
|||
|
||||
_drapeEngineCreated = YES;
|
||||
|
||||
NSLog(@"EAGLView createDrapeEngine Ended");
|
||||
LOG(LINFO, ("EAGLView createDrapeEngine Ended"));
|
||||
}
|
||||
|
||||
- (void)addSubview:(UIView *)view
|
||||
|
|
|
@ -3,17 +3,22 @@
|
|||
#import "iosOGLContext.h"
|
||||
#import "../../../../drape/oglcontextfactory.hpp"
|
||||
|
||||
#include "std/condition_variable.hpp"
|
||||
#include "std/mutex.hpp"
|
||||
|
||||
class iosOGLContextFactory: public dp::OGLContextFactory
|
||||
{
|
||||
public:
|
||||
iosOGLContextFactory(CAEAGLLayer * layer);
|
||||
~iosOGLContextFactory();
|
||||
|
||||
virtual dp::OGLContext * getDrawContext();
|
||||
virtual dp::OGLContext * getResourcesUploadContext();
|
||||
dp::OGLContext * getDrawContext() override;
|
||||
dp::OGLContext * getResourcesUploadContext() override;
|
||||
|
||||
virtual bool isDrawContextCreated() const;
|
||||
virtual bool isUploadContextCreated() const;
|
||||
bool isDrawContextCreated() const override;
|
||||
bool isUploadContextCreated() const override;
|
||||
|
||||
void waitForInitialization() override;
|
||||
|
||||
void setPresentAvailable(bool available);
|
||||
|
||||
|
@ -21,4 +26,8 @@ private:
|
|||
CAEAGLLayer * m_layer;
|
||||
iosOGLContext * m_drawContext;
|
||||
iosOGLContext * m_uploadContext;
|
||||
};
|
||||
|
||||
bool m_isInitialized;
|
||||
condition_variable m_initializationCondition;
|
||||
mutex m_initializationMutex;
|
||||
};
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
iosOGLContextFactory::iosOGLContextFactory(CAEAGLLayer * layer)
|
||||
: m_layer(layer)
|
||||
, m_drawContext(NULL)
|
||||
, m_uploadContext(NULL)
|
||||
, m_drawContext(nullptr)
|
||||
, m_uploadContext(nullptr)
|
||||
, m_isInitialized(false)
|
||||
{}
|
||||
|
||||
iosOGLContextFactory::~iosOGLContextFactory()
|
||||
|
@ -14,14 +15,14 @@ iosOGLContextFactory::~iosOGLContextFactory()
|
|||
|
||||
dp::OGLContext * iosOGLContextFactory::getDrawContext()
|
||||
{
|
||||
if (m_drawContext == NULL)
|
||||
if (m_drawContext == nullptr)
|
||||
m_drawContext = new iosOGLContext(m_layer, m_uploadContext, true);
|
||||
return m_drawContext;
|
||||
}
|
||||
|
||||
dp::OGLContext * iosOGLContextFactory::getResourcesUploadContext()
|
||||
{
|
||||
if (m_uploadContext == NULL)
|
||||
if (m_uploadContext == nullptr)
|
||||
m_uploadContext = new iosOGLContext(m_layer, m_drawContext, false);
|
||||
return m_uploadContext;
|
||||
}
|
||||
|
@ -38,6 +39,20 @@ bool iosOGLContextFactory::isUploadContextCreated() const
|
|||
|
||||
void iosOGLContextFactory::setPresentAvailable(bool available)
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lock(m_initializationMutex);
|
||||
if (!m_isInitialized && available)
|
||||
{
|
||||
m_isInitialized = true;
|
||||
m_initializationCondition.notify_one();
|
||||
}
|
||||
}
|
||||
if (m_drawContext != nullptr)
|
||||
m_drawContext->setPresentAvailable(available);
|
||||
}
|
||||
|
||||
void iosOGLContextFactory::waitForInitialization()
|
||||
{
|
||||
unique_lock<mutex> lock(m_initializationMutex);
|
||||
m_initializationCondition.wait(lock, [this] { return m_isInitialized; });
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue