Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Fix crash when setting beam color (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemarvin authored Apr 20, 2019
1 parent 73031c8 commit 176cc73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/src/main/cpp/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Controller::operator=(const Controller& aController) {
scrollDeltaY = aController.scrollDeltaY;
transform = aController.transform;
beamToggle = aController.beamToggle;
beamParent = aController.beamParent;
pointer = aController.pointer;
transformMatrix = aController.transformMatrix;
beamTransformMatrix = aController.beamTransformMatrix;
Expand Down Expand Up @@ -75,6 +76,7 @@ Controller::Reset() {
scrollDeltaX = scrollDeltaY = 0.0f;
transform = nullptr;
beamToggle = nullptr;
beamParent = nullptr;
pointer = nullptr;
transformMatrix = Matrix::Identity();
beamTransformMatrix = Matrix::Identity();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct Controller {
float scrollDeltaY;
vrb::TransformPtr transform;
vrb::TogglePtr beamToggle;
vrb::GroupPtr beamParent;
PointerPtr pointer;
vrb::Matrix transformMatrix;
vrb::Matrix beamTransformMatrix;
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/cpp/ControllerContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ ControllerContainer::CreateController(const int32_t aControllerIndex, const int3
if (m.beamModel) {
controller.beamToggle = vrb::Toggle::Create(create);
if (aBeamTransform.IsIdentity()) {
controller.beamParent = controller.beamParent;
controller.beamToggle->AddNode(m.beamModel);
} else {
vrb::TransformPtr beamTransform = Transform::Create(create);
beamTransform->SetTransform(aBeamTransform);
beamTransform->AddNode(m.beamModel);
controller.beamParent = beamTransform;
controller.beamToggle->AddNode(beamTransform);
}
controller.transform->AddNode(controller.beamToggle);
Expand Down Expand Up @@ -364,9 +366,11 @@ ControllerContainer::SetScrolledDelta(const int32_t aControllerIndex, const floa

void ControllerContainer::SetPointerColor(const vrb::Color& aColor) const {
for (Controller& controller: m.list) {
if (controller.transform) {
GeometryPtr geometry = std::dynamic_pointer_cast<vrb::Geometry>(controller.transform->GetNode(1));
geometry->GetRenderState()->SetMaterial(aColor, aColor, vrb::Color(0.0f, 0.0f, 0.0f), 0.0f);
if (controller.beamParent) {
GeometryPtr geometry = std::dynamic_pointer_cast<vrb::Geometry>(controller.beamParent->GetNode(0));
if (geometry) {
geometry->GetRenderState()->SetMaterial(aColor, aColor, vrb::Color(0.0f, 0.0f, 0.0f), 0.0f);
}
}
if (controller.pointer) {
controller.pointer->SetPointerColor(aColor);
Expand Down

0 comments on commit 176cc73

Please sign in to comment.