Skip to content

Commit

Permalink
Fix deprecated use of ALooper_PollAll (#139)
Browse files Browse the repository at this point in the history
Issue: #133

Fix double spawn with multiple controllers

Issue #137
  • Loading branch information
rbessems authored Oct 1, 2024
1 parent 28e2dd4 commit e493c17
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Chapter1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class OpenXRTutorial {
int events = 0;
// The timeout depends on whether the application is active.
const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0;
if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) {
if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) {
if (source != nullptr) {
source->process(androidApp, source);
}
Expand Down
2 changes: 1 addition & 1 deletion Chapter2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class OpenXRTutorial {
int events = 0;
// The timeout depends on whether the application is active.
const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0;
if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) {
if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) {
if (source != nullptr) {
source->process(androidApp, source);
}
Expand Down
2 changes: 1 addition & 1 deletion Chapter3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ class OpenXRTutorial {
int events = 0;
// The timeout depends on whether the application is active.
const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0;
if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) {
if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) {
if (source != nullptr) {
source->process(androidApp, source);
}
Expand Down
8 changes: 5 additions & 3 deletions Chapter4/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class OpenXRTutorial {
// Each Action here has two paths, one for each SubAction path.
any_ok |= SuggestBindings("/interaction_profiles/khr/simple_controller", {{m_changeColorAction, CreateXrPath("/user/hand/left/input/select/click")},
{m_grabCubeAction, CreateXrPath("/user/hand/right/input/select/click")},
{m_spawnCubeAction, CreateXrPath("/user/hand/right/input/menu/click")},
{m_palmPoseAction, CreateXrPath("/user/hand/left/input/grip/pose")},
{m_palmPoseAction, CreateXrPath("/user/hand/right/input/grip/pose")},
{m_buzzAction, CreateXrPath("/user/hand/left/output/haptic")},
Expand Down Expand Up @@ -894,8 +895,9 @@ class OpenXRTutorial {
thisBlock.color = color;
}
} else {
// not near a block? We can spawn one.
if (m_spawnCubeState.isActive == XR_TRUE && m_spawnCubeState.currentState == XR_FALSE && m_spawnCubeState.changedSinceLastSync == XR_TRUE) {
// right hand not near a block?
// i = 1 means sub action path /user/hand/right
if (i == 1 && m_spawnCubeState.isActive == XR_TRUE && m_spawnCubeState.currentState == XR_FALSE && m_spawnCubeState.changedSinceLastSync == XR_TRUE) {
XrQuaternionf q = {0.0f, 0.0f, 0.0f, 1.0f};
XrVector3f color = {pseudorandom_distribution(pseudo_random_generator), pseudorandom_distribution(pseudo_random_generator), pseudorandom_distribution(pseudo_random_generator)};
m_blocks.push_back({{q, FixPosition(m_handPose[i].position)}, {0.095f, 0.095f, 0.095f}, color});
Expand Down Expand Up @@ -1330,7 +1332,7 @@ class OpenXRTutorial {
int events = 0;
// The timeout depends on whether the application is active.
const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0;
if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) {
if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) {
if (source != nullptr) {
source->process(androidApp, source);
}
Expand Down
2 changes: 1 addition & 1 deletion Chapter5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ class OpenXRTutorial {
int events = 0;
// The timeout depends on whether the application is active.
const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0;
if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) {
if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) {
if (source != nullptr) {
source->process(androidApp, source);
}
Expand Down
2 changes: 1 addition & 1 deletion Chapter6_1_Multiview/Chapter6/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ class OpenXRTutorial {
int events = 0;
// The timeout depends on whether the application is active.
const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0;
if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) {
if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) {
if (source != nullptr) {
source->process(androidApp, source);
}
Expand Down

0 comments on commit e493c17

Please sign in to comment.