From d64258295612982547ae779b112c083855e658d2 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Tue, 24 Mar 2015 20:41:38 +0100 Subject: [PATCH] Protecting some functions with the light_mutex. --- game/level.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/game/level.cc b/game/level.cc index 86aa9eb..6ddeddc 100644 --- a/game/level.cc +++ b/game/level.cc @@ -372,6 +372,7 @@ glm::vec3 Level::getAmbientLight() { } std::vector* Level::getLights() { + std::lock_guard lock(light_mutex); return &lights; } @@ -508,6 +509,7 @@ void Level::setCameraCenter(Object* object) { } void Level::addLight(Light light) { + std::lock_guard lock(light_mutex); Light *add_light = new Light(light); this->lights.push_back(add_light); } @@ -517,11 +519,13 @@ void Level::preloadLightPosition(float xPos, float yPos, float zPos){ } void Level::addLightByParameters(float redColour, float greenColour, float blueColour, float intensity, float flameYOffset, float flameHeight, float flameWidth){ + std::lock_guard lock(light_mutex); glm::vec3 colour = glm::vec3(redColour, greenColour, blueColour); this->lights.push_back(new Light(nextLightPosition, colour, intensity, flameYOffset, flameHeight, flameWidth)); } void Level::deleteFourLights(){ + std::lock_guard lock(light_mutex); int indice = lights.size()-4; lights.erase(lights.begin() + indice); lights.erase(lights.begin() + indice); @@ -612,6 +616,7 @@ bool Level::compareLightDistances(Light* a, Light* b) { } std::vector* Level::getClosestLights() { + std::lock_guard lock(light_mutex); closestLights = std::vector(lights); std::sort(closestLights.begin(), closestLights.end(),