Skip to content

Commit

Permalink
crash fix: render thread accessing Lua game state
Browse files Browse the repository at this point in the history
  • Loading branch information
Mormert committed Apr 7, 2024
1 parent 2d5ba78 commit c4f905f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
10 changes: 6 additions & 4 deletions engine/editor/jleEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,20 @@ jleEditor::start()
}

void
jleEditor::render()
jleEditor::render(wi::jobsystem::context& ctx)
{
JLE_SCOPE_PROFILE_GPU(EditorRender);

renderGameView();

//renderEditorGizmos();

//renderEditorGridGizmo();
renderEditorGridGizmo();

renderEditorSceneView();

// UI can touch game state, so we need to for game logic update to complete
Wait(ctx);

renderEditorGizmos();
renderEditorUI();

//resetRenderGraphForNewFrame();
Expand Down
2 changes: 1 addition & 1 deletion engine/editor/jleEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class jleEditor : public jleGameEngine

void start() override;

void render() override;
void render(wi::jobsystem::context& ctx) override;

void update(float dt) override;

Expand Down
13 changes: 9 additions & 4 deletions engine/jleGameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,14 @@ jleGameEngine::executeNextFrame()
LOG_VERBOSE << "Next frame dt: " << gEngine->deltaFrameTime();
auto gameHaltedTemp = gameHalted;
gameHalted = false;
update(deltaFrameTime());

JLE_EXEC_IF_NOT(JLE_BUILD_HEADLESS) { render(); }
wi::jobsystem::context ctx;

// Game thread
wi::jobsystem::Execute(ctx, [&](wi::jobsystem::JobArgs args) { update(deltaFrameTime()); });

// Render thread
JLE_EXEC_IF_NOT(JLE_BUILD_HEADLESS) { render(ctx); }
gameHalted = gameHaltedTemp;
}

Expand Down Expand Up @@ -367,7 +372,7 @@ jleGameEngine::update(float dt)
}

void
jleGameEngine::render()
jleGameEngine::render(wi::jobsystem::context& ctx)
{
JLE_SCOPE_PROFILE_CPU(jleGameEngine_render)

Expand Down Expand Up @@ -450,7 +455,7 @@ jleGameEngine::mainLoop()
// Render thread
JLE_EXEC_IF_NOT(JLE_BUILD_HEADLESS)
{
render();
render(ctx);
_window->updateWindow();
running = !_window->windowShouldClose();
}
Expand Down
9 changes: 7 additions & 2 deletions engine/jleGameEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#include "jleCommon.h"

#include <functional>
#include <memory>
#include <unordered_map>
#include <functional>

namespace SoLoud
{
Expand All @@ -30,6 +30,11 @@ namespace Rml
class Context;
};

namespace wi::jobsystem
{
struct context;
}

class jleGame;
class jleResources;
class jleEngineSettings;
Expand Down Expand Up @@ -152,7 +157,7 @@ class jleGameEngine

virtual void update(float dt);

virtual void render();
virtual void render(wi::jobsystem::context& ctx);

virtual void exiting();

Expand Down

0 comments on commit c4f905f

Please sign in to comment.