From ad377e6256bde405aea9f93e98b37b5f495c6fe4 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 4 Jun 2013 17:25:04 -0700 Subject: [PATCH] We can't initialize avatars from the network thread; they need access to the OpenGL context. --- interface/src/Application.cpp | 10 +++++++--- interface/src/Avatar.cpp | 2 ++ interface/src/Avatar.h | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6f898ecae7..2aae2353c5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1083,6 +1083,9 @@ void Application::idle() { for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL) { Avatar *avatar = (Avatar *)agent->getLinkedData(); + if (!avatar->isInitialized()) { + avatar->init(); + } avatar->simulate(deltaTime, NULL); avatar->setMouseRay(mouseRayOrigin, mouseRayDirection); } @@ -2061,6 +2064,9 @@ void Application::displaySide(Camera& whichCamera) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *avatar = (Avatar *)agent->getLinkedData(); + if (!avatar->isInitialized()) { + avatar->init(); + } avatar->render(false); } } @@ -2534,9 +2540,7 @@ QAction* Application::checkedVoxelModeAction() const { void Application::attachNewHeadToAgent(Agent* newAgent) { if (newAgent->getLinkedData() == NULL) { - Avatar* newAvatar = new Avatar(newAgent); - newAvatar->init(); - newAgent->setLinkedData(newAvatar); + newAgent->setLinkedData(new Avatar(newAgent)); } } diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 4a3e8db2bc..7b2c94d152 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -62,6 +62,7 @@ float chatMessageHeight = 0.20; Avatar::Avatar(Agent* owningAgent) : AvatarData(owningAgent), + _initialized(false), _head(this), _ballSpringsInitialized(false), _TEST_bigSphereRadius(0.5f), @@ -266,6 +267,7 @@ Avatar::~Avatar() { void Avatar::init() { _voxels.init(); + _initialized = true; } void Avatar::reset() { diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 20c431ef82..e27462ee49 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -100,6 +100,7 @@ public: void setOrientation (const glm::quat& orientation); //getters + bool isInitialized () const { return _initialized;} const Skeleton& getSkeleton () const { return _skeleton;} float getHeadYawRate () const { return _head.yawRate;} float getBodyYaw () const { return _bodyYaw;} @@ -156,6 +157,7 @@ private: float touchForce; // a scalar determining the amount that the cursor (or hand) is penetrating the ball }; + bool _initialized; Head _head; Skeleton _skeleton; bool _ballSpringsInitialized;