mirror of https://github.com/auygun/kaliber.git
Fix for crash in renderer
This commit is contained in:
parent
7d458859d7
commit
29ce485ca3
|
@ -73,6 +73,17 @@ void Engine::Run() {
|
|||
float frame_frac = 0.0f;
|
||||
|
||||
for (;;) {
|
||||
TaskRunner::GetThreadLocalTaskRunner()->SingleConsumerRun();
|
||||
|
||||
platform_->Update();
|
||||
if (platform_->should_exit())
|
||||
return;
|
||||
|
||||
if (!renderer_->IsInitialzed()) {
|
||||
timer_.Reset();
|
||||
continue;
|
||||
}
|
||||
|
||||
Draw(frame_frac);
|
||||
|
||||
// Accumulate time.
|
||||
|
@ -81,13 +92,8 @@ void Engine::Run() {
|
|||
|
||||
// Subdivide the frame time using fixed time steps.
|
||||
while (accumulator >= time_step_) {
|
||||
TaskRunner::GetThreadLocalTaskRunner()->SingleConsumerRun();
|
||||
platform_->Update();
|
||||
Update(time_step_);
|
||||
accumulator -= time_step_;
|
||||
|
||||
if (platform_->should_exit())
|
||||
return;
|
||||
};
|
||||
|
||||
// Calculate frame fraction from remainder of the frame time.
|
||||
|
|
|
@ -199,7 +199,6 @@ class Engine : public PlatformObserver {
|
|||
int fps_ = 0;
|
||||
|
||||
float seconds_accumulated_ = 0.0f;
|
||||
|
||||
float time_step_ = 1.0f / 60.0f;
|
||||
size_t tick_ = 0;
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ RendererOpenGL::~RendererOpenGL() {
|
|||
}
|
||||
|
||||
void RendererOpenGL::Shutdown() {
|
||||
is_initialized_ = false;
|
||||
|
||||
#ifdef THREADED_RENDERING
|
||||
if (terminate_render_thread_)
|
||||
return;
|
||||
|
@ -313,6 +315,8 @@ bool RendererOpenGL::InitCommon() {
|
|||
|
||||
glClearColor(0, 0, 0, 1);
|
||||
|
||||
is_initialized_ = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,11 @@ class RendererOpenGL final : public Renderer {
|
|||
RendererOpenGL(base::Closure context_lost_cb);
|
||||
~RendererOpenGL() final;
|
||||
|
||||
virtual bool Initialize(Platform* platform) final;
|
||||
bool Initialize(Platform* platform) final;
|
||||
void Shutdown() final;
|
||||
|
||||
bool IsInitialzed() const final { return is_initialized_; }
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
void DestroyGeometry(uint64_t resource_id) final;
|
||||
void Draw(uint64_t resource_id) final;
|
||||
|
@ -124,6 +126,8 @@ class RendererOpenGL final : public Renderer {
|
|||
bool vertex_array_objects_ = false;
|
||||
bool npot_ = false;
|
||||
|
||||
bool is_initialized_ = false;
|
||||
|
||||
#ifdef THREADED_RENDERING
|
||||
// Global commands are independent from frames and guaranteed to be processed.
|
||||
std::deque<std::unique_ptr<RenderCommand>> global_commands_;
|
||||
|
|
|
@ -26,6 +26,8 @@ class Renderer {
|
|||
virtual bool Initialize(Platform* platform) = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
virtual bool IsInitialzed() const = 0;
|
||||
|
||||
virtual uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) = 0;
|
||||
virtual void DestroyGeometry(uint64_t resource_id) = 0;
|
||||
virtual void Draw(uint64_t resource_id) = 0;
|
||||
|
|
|
@ -23,9 +23,11 @@ class RendererVulkan final : public Renderer {
|
|||
RendererVulkan(base::Closure context_lost_cb);
|
||||
~RendererVulkan() final;
|
||||
|
||||
virtual bool Initialize(Platform* platform) final;
|
||||
bool Initialize(Platform* platform) final;
|
||||
void Shutdown() final;
|
||||
|
||||
bool IsInitialzed() const final { return device_ != VK_NULL_HANDLE; }
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
void DestroyGeometry(uint64_t resource_id) final;
|
||||
void Draw(uint64_t resource_id) final;
|
||||
|
|
Loading…
Reference in New Issue