File tree Expand file tree Collapse file tree 5 files changed +15
-1
lines changed
Expand file tree Collapse file tree 5 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ class EventListener {
4040 static std::condition_variable startedCond;
4141 static std::mutex doneMutex;
4242 static std::condition_variable doneCond;
43+ static std::mutex renderMutex;
4344 void setPainter (std::function<void ()> f);
4445 void paint ();
4546private:
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ std::mutex EventListener::startMutex;
2525std::condition_variable EventListener::startedCond;
2626std::mutex EventListener::doneMutex;
2727std::condition_variable EventListener::doneCond;
28+ std::mutex EventListener::renderMutex;
2829
2930#define SIZE_MOVE_TIMER_ID 1
3031#if defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__)
@@ -52,12 +53,15 @@ EventListener::~EventListener()
5253}
5354void EventListener::setPainter (std::function<void ()> f)
5455{
56+ std::unique_lock<std::mutex> lock (renderMutex);
5557 painter = f;
5658}
5759void EventListener::paint ()
5860{
5961 if (painter)
6062 {
63+ std::unique_lock<std::mutex> lock (renderMutex);
64+ gfx->createGLContext ();
6165 painter ();
6266 gfx->nextFrame ();
6367 }
Original file line number Diff line number Diff line change 2121#include < Toolkit.h>
2222#include < FileManager.h>
2323#include < SupportFunctions.h>
24+ #include " EventListener.h"
2425#include < assert.h>
2526#include < string>
2627#include < sstream>
@@ -2060,6 +2061,7 @@ namespace GAGCore
20602061 }
20612062
20622063 SDL_Surface* GraphicContext::getOrCreateSurface (int w, int h, Uint32 flags) {
2064+ std::unique_lock<std::mutex> lock (EventListener::instance ()->renderMutex );
20632065 if (flags & USEGPU)
20642066 {
20652067 if (sdlsurface)
Original file line number Diff line number Diff line change @@ -508,6 +508,14 @@ int Engine::run(void)
508508 if (nextGuiStep == 0 )
509509 {
510510 // we draw
511+ static bool isPainterSet = false ;
512+ if (!isPainterSet)
513+ {
514+ EventListener::instance ()->setPainter (std::bind (GameGUI::drawAll, &gui, gui.localTeamNo ));
515+ isPainterSet = true ;
516+ }
517+ std::unique_lock<std::mutex> lock (EventListener::instance ()->renderMutex );
518+ globalContainer->gfx ->createGLContext ();
511519 gui.drawAll (gui.localTeamNo );
512520 globalContainer->gfx ->nextFrame ();
513521 }
Original file line number Diff line number Diff line change @@ -4380,7 +4380,6 @@ void GameGUI::drawInGameScrollableText(void)
43804380
43814381void GameGUI::drawAll (int team)
43824382{
4383- EventListener::instance ()->setPainter (std::bind (&GameGUI::drawAll, this , team));
43844383 // draw the map
43854384 Uint32 drawOptions = (drawHealthFoodBar ? Game::DRAW_HEALTH_FOOD_BAR : 0 ) |
43864385 (drawPathLines ? Game::DRAW_PATH_LINE : 0 ) |
You can’t perform that action at this time.
0 commit comments