Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Change the timing of vrapi_SetDisplayRefreshRate because Ovr == NULL …
Browse files Browse the repository at this point in the history
…on calling. Maybe fix #116 #197
  • Loading branch information
polygraphene committed Oct 3, 2018
1 parent d24b646 commit e2ba009
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 27 deletions.
12 changes: 12 additions & 0 deletions ALVR-common/common-utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common-utils.h"

std::wstring ToWstring(const std::string &src) {
// TODO: src is really UTF-8?
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.from_bytes(src);
}

std::string ToUTF8(const std::wstring &src) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.to_bytes(src);
}
8 changes: 8 additions & 0 deletions ALVR-common/common-utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <string>
#include <locale>
#include <codecvt>

std::wstring ToWstring(const std::string &src);
std::string ToUTF8(const std::wstring &src);
34 changes: 34 additions & 0 deletions ALVR-common/exception.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdarg.h>
#include <wchar.h>
#include "exception.h"
#include "common-utils.h"

Exception FormatExceptionV(const wchar_t *format, va_list args) {
wchar_t buf[10000];
#ifdef _WIN32_
_vsnwprintf_s(buf, sizeof(buf) / sizeof(buf[0]), format, args);
#else
vswprintf(buf, sizeof(buf) / sizeof(buf[0]), format, args);
#endif
return Exception(buf);
}

Exception FormatExceptionV(const char *format, va_list args) {
char buf[10000];

#ifdef _WIN32_
_vsnprintf_s(buf, sizeof(buf) / sizeof(buf[0]), format, args);
#else
vsnprintf(buf, sizeof(buf) / sizeof(buf[0]), format, args);
#endif
return Exception(ToWstring(buf));
}

Exception FormatException(const char *format, ...) {
va_list args;
va_start(args, format);
Exception e = FormatExceptionV(format, args);
va_end(args);

return e;
}
34 changes: 15 additions & 19 deletions ALVR-common/exception.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
#pragma once

#include <string>

class Exception : public std::exception {
public:
Exception(std::string what)
Exception(std::wstring what)
: m_what(what) {
}
Exception() {
}

virtual const char *what() {
virtual const wchar_t *what() {
return m_what.c_str();
}

Exception& operator=(const Exception &src) {
m_what = src.m_what;
return *this;
}
private:
const std::string m_what;
std::wstring m_what;
};

inline Exception FormatException(const char *format, ...) {
va_list args;
va_start(args, format);
char buf[10000];
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);

return Exception(buf);
}

inline Exception FormatExceptionV(const char *format, va_list args) {
char buf[10000];
vsnprintf(buf, sizeof(buf), format, args);

return Exception(buf);
}
Exception FormatExceptionV(const wchar_t *format, va_list args);
Exception FormatExceptionV(const char *format, va_list args);
Exception FormatException(const char *format, ...);
2 changes: 2 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ add_library( # Sets the name of the library.
src/main/cpp/asset.cpp
src/main/cpp/gltf_model.cpp
../ALVR-common/reedsolomon/rs.c
../ALVR-common/common-utils.cpp
../ALVR-common/exception.cpp
)

# Searches for a specified prebuilt library and stores the path as a
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ Java_com_polygraphene_alvr_UdpReceiverThread_initializeSocket(JNIEnv *env, jobje
try {
g_udpManager->initialize(env, port, deviceName_, broadcastAddrList_, is72Hz);
} catch (Exception e) {
LOGE("Exception on initializing UdpManager. e=%s", e.what());
LOGE("Exception on initializing UdpManager. e=%ls", e.what());
return 1;
}
return 0;
Expand Down
15 changes: 8 additions & 7 deletions app/src/main/cpp/vr_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ void VrContext::onVrModeChange() {
return;
}

if (support72hz) {
LOG("Use 72 Hz refresh rate.");
ovrResult result = vrapi_SetDisplayRefreshRate(Ovr, 72.0f);
LOG("vrapi_SetDisplayRefreshRate: Result=%d", result);
} else {
LOG("Use 60 Hz refresh rate.");
}

int CpuLevel = 3;
int GpuLevel = 3;
vrapi_SetClockLevels(Ovr, CpuLevel, GpuLevel);
Expand Down Expand Up @@ -78,13 +86,6 @@ void VrContext::chooseRefreshRate() {
}
}
LOG("Supported refresh rates: %s", refreshRateList.c_str());

if (support72hz) {
LOG("Use 72 Hz refresh rate.");
vrapi_SetDisplayRefreshRate(Ovr, 72.0f);
} else {
LOG("Use 60 Hz refresh rate.");
}
}

void VrContext::initialize(JNIEnv *env, jobject activity, jobject assetManager, bool ARMode) {
Expand Down

0 comments on commit e2ba009

Please sign in to comment.