Fix for crash in renderer

This commit is contained in:
Attila Uygun 2023-06-02 14:23:21 +02:00
parent 7d458859d7
commit 29ce485ca3
6 changed files with 25 additions and 8 deletions

View File

@ -73,6 +73,17 @@ void Engine::Run() {
float frame_frac = 0.0f; float frame_frac = 0.0f;
for (;;) { for (;;) {
TaskRunner::GetThreadLocalTaskRunner()->SingleConsumerRun();
platform_->Update();
if (platform_->should_exit())
return;
if (!renderer_->IsInitialzed()) {
timer_.Reset();
continue;
}
Draw(frame_frac); Draw(frame_frac);
// Accumulate time. // Accumulate time.
@ -81,13 +92,8 @@ void Engine::Run() {
// Subdivide the frame time using fixed time steps. // Subdivide the frame time using fixed time steps.
while (accumulator >= time_step_) { while (accumulator >= time_step_) {
TaskRunner::GetThreadLocalTaskRunner()->SingleConsumerRun();
platform_->Update();
Update(time_step_); Update(time_step_);
accumulator -= time_step_; accumulator -= time_step_;
if (platform_->should_exit())
return;
}; };
// Calculate frame fraction from remainder of the frame time. // Calculate frame fraction from remainder of the frame time.

View File

@ -199,7 +199,6 @@ class Engine : public PlatformObserver {
int fps_ = 0; int fps_ = 0;
float seconds_accumulated_ = 0.0f; float seconds_accumulated_ = 0.0f;
float time_step_ = 1.0f / 60.0f; float time_step_ = 1.0f / 60.0f;
size_t tick_ = 0; size_t tick_ = 0;

View File

@ -53,6 +53,8 @@ RendererOpenGL::~RendererOpenGL() {
} }
void RendererOpenGL::Shutdown() { void RendererOpenGL::Shutdown() {
is_initialized_ = false;
#ifdef THREADED_RENDERING #ifdef THREADED_RENDERING
if (terminate_render_thread_) if (terminate_render_thread_)
return; return;
@ -313,6 +315,8 @@ bool RendererOpenGL::InitCommon() {
glClearColor(0, 0, 0, 1); glClearColor(0, 0, 0, 1);
is_initialized_ = true;
return true; return true;
} }

View File

@ -40,9 +40,11 @@ class RendererOpenGL final : public Renderer {
RendererOpenGL(base::Closure context_lost_cb); RendererOpenGL(base::Closure context_lost_cb);
~RendererOpenGL() final; ~RendererOpenGL() final;
virtual bool Initialize(Platform* platform) final; bool Initialize(Platform* platform) final;
void Shutdown() final; void Shutdown() final;
bool IsInitialzed() const final { return is_initialized_; }
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final; uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
void DestroyGeometry(uint64_t resource_id) final; void DestroyGeometry(uint64_t resource_id) final;
void Draw(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 vertex_array_objects_ = false;
bool npot_ = false; bool npot_ = false;
bool is_initialized_ = false;
#ifdef THREADED_RENDERING #ifdef THREADED_RENDERING
// Global commands are independent from frames and guaranteed to be processed. // Global commands are independent from frames and guaranteed to be processed.
std::deque<std::unique_ptr<RenderCommand>> global_commands_; std::deque<std::unique_ptr<RenderCommand>> global_commands_;

View File

@ -26,6 +26,8 @@ class Renderer {
virtual bool Initialize(Platform* platform) = 0; virtual bool Initialize(Platform* platform) = 0;
virtual void Shutdown() = 0; virtual void Shutdown() = 0;
virtual bool IsInitialzed() const = 0;
virtual uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) = 0; virtual uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) = 0;
virtual void DestroyGeometry(uint64_t resource_id) = 0; virtual void DestroyGeometry(uint64_t resource_id) = 0;
virtual void Draw(uint64_t resource_id) = 0; virtual void Draw(uint64_t resource_id) = 0;

View File

@ -23,9 +23,11 @@ class RendererVulkan final : public Renderer {
RendererVulkan(base::Closure context_lost_cb); RendererVulkan(base::Closure context_lost_cb);
~RendererVulkan() final; ~RendererVulkan() final;
virtual bool Initialize(Platform* platform) final; bool Initialize(Platform* platform) final;
void Shutdown() final; void Shutdown() final;
bool IsInitialzed() const final { return device_ != VK_NULL_HANDLE; }
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final; uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
void DestroyGeometry(uint64_t resource_id) final; void DestroyGeometry(uint64_t resource_id) final;
void Draw(uint64_t resource_id) final; void Draw(uint64_t resource_id) final;