History

Additional thread safety

Brad Davis committed 9 years ago

Commit 8372d731 parent b52dd7b23 files · +413 −249Browse files

Showing the changes to interface/src/scripting/HMDScriptingInterface.cpp (1 of 23 files). Show all

Unified · Split

interface/src/scripting/HMDScriptingInterface.cpp+21−11
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313
1414 #include <QtScript/QScriptContext>
1515
16+#include <shared/QtHelpers.h>
1617 #include <avatar/AvatarManager.h>
1718 #include <display-plugins/DisplayPlugin.h>
1819 #include <display-plugins/CompositorHelper.h>
@@ -152,22 +153,31 @@ QString HMDScriptingInterface::preferredAudioOutput() const { · 133 unmodified lines
152153 return qApp->getActiveDisplayPlugin()->getPreferredAudioOutDevice();
153154 }
154155
155−bool HMDScriptingInterface::setHandLasers(int hands, bool enabled, const glm::vec4& color, const glm::vec3& direction) const {
156+bool HMDScriptingInterface::setHandLasers(int hands, bool enabled, const glm::vec4& color, const glm::vec3& direction) {
157+ if (QThread::currentThread() != thread()) {
158+ bool result;
159+ hifi::qt::blockingInvokeMethod(this, "setHandLasers", Q_RETURN_ARG(bool, result),
160+ Q_ARG(int, hands), Q_ARG(bool, enabled), Q_ARG(glm::vec4, color), Q_ARG(glm::vec3, direction));
161+ return result;
162+ }
163+
156164 auto offscreenUi = DependencyManager::get<OffscreenUi>();
157− offscreenUi->executeOnUiThread([offscreenUi, enabled] {
158− offscreenUi->getDesktop()->setProperty("hmdHandMouseActive", enabled);
159− });
165+ offscreenUi->getDesktop()->setProperty("hmdHandMouseActive", enabled);
160166 return qApp->getActiveDisplayPlugin()->setHandLaser(hands,
161167 enabled ? DisplayPlugin::HandLaserMode::Overlay : DisplayPlugin::HandLaserMode::None,
162168 color, direction);
163169 }
164170
165−bool HMDScriptingInterface::setExtraLaser(const glm::vec3& worldStart, bool enabled, const glm::vec4& color, const glm::vec3& direction) const {
166− auto offscreenUi = DependencyManager::get<OffscreenUi>();
167− offscreenUi->executeOnUiThread([offscreenUi, enabled] {
168− offscreenUi->getDesktop()->setProperty("hmdHandMouseActive", enabled);
169− });
171+bool HMDScriptingInterface::setExtraLaser(const glm::vec3& worldStart, bool enabled, const glm::vec4& color, const glm::vec3& direction) {
172+ if (QThread::currentThread() != thread()) {
173+ bool result;
174+ hifi::qt::blockingInvokeMethod(this, "setExtraLaser", Q_RETURN_ARG(bool, result),
175+ Q_ARG(glm::vec3, worldStart), Q_ARG(bool, enabled), Q_ARG(glm::vec4, color), Q_ARG(glm::vec3, direction));
176+ return result;
177+ }
170178
179+ auto offscreenUi = DependencyManager::get<OffscreenUi>();
180+ offscreenUi->getDesktop()->setProperty("hmdHandMouseActive", enabled);
171181
172182 auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
173183 auto sensorToWorld = myAvatar->getSensorToWorldMatrix();
@@ -179,11 +189,11 @@ bool HMDScriptingInterface::setExtraLaser(const glm::vec3& worldStart, bool enab · 5 unmodified lines
179189 color, sensorStart, sensorDirection);
180190 }
181191
182−void HMDScriptingInterface::disableExtraLaser() const {
192+void HMDScriptingInterface::disableExtraLaser() {
183193 setExtraLaser(vec3(0), false, vec4(0), vec3(0));
184194 }
185195
186−void HMDScriptingInterface::disableHandLasers(int hands) const {
196+void HMDScriptingInterface::disableHandLasers(int hands) {
187197 setHandLasers(hands, false, vec4(0), vec3(0));
188198 }
189199