cancel
Showing results for 
Search instead for 
Did you mean: 

ovr_CreateTextureSwapChainGL() failed

SpaceEngineer
Explorer
So every tine I attempt to create the swap chains, I got the error code ovrError_InvalidParameter == -1005 with the following message returned by ovr_GetLastErrorInfo():
BindFlags not supported for OpenGL applications.

I am using Oculus DK2 with the SDK 1.20 and latest NVidia drivers. This issue started many months ago, probably since 1.12 or so.

The code is a direct copy-paste from the OculusRoomTiny (GL) sample, or from the Texture Swap Chain Initialization documentation:



    ovrTextureSwapChainDesc desc = {};
desc.Type = ovrTexture_2D;
desc.ArraySize = 1;
desc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
desc.Width = w;
desc.Height = h;
desc.MipLevels = 1;
desc.SampleCount = 1;
desc.StaticImage = ovrFalse;
desc.MiscFlags = ovrTextureMisc_None; // Tried a direct assignment, but still fail
desc.BindFlags = ovrTextureBind_None; // Tried a direct assignment, but still fail

ovrResult res = ovr_CreateTextureSwapChainGL(session, &desc, &swapTextures);
// res is always ovrError_InvalidParameter

The initialization sequence is following (I am skipping error checks for clarity):

    ovr_Detect(0);

ovrInitParams params = { ovrInit_Debug | ovrInit_RequestVersion, OVR_MINOR_VERSION, OculusLogCallback, 0, 0 };
ovr_Initialize(&params);

ovrGraphicsLuid luid;
ovr_Create(&hmdSession, &luid);

//------------------------------------
// in the function called at WM_CREATE message:
<Create core GL context, make current>
<init GLEW library>
//------------------------------------

hmdDesc = ovr_GetHmdDesc(hmdSession);

ovrSizei ResLeft = ovr_GetFovTextureSize(hmdSession, ovrEye_Left, hmdDesc.DefaultEyeFov[0], 1.0f);
ovrSizei ResRight = ovr_GetFovTextureSize(hmdSession, ovrEye_Right, hmdDesc.DefaultEyeFov[1], 1.0f);
int w = max(ResLeft.w, ResRight.w); // 1184
int h = max(ResLeft.h, ResRight.h); // 1472

for (int eyeIdx = 0; eyeIdx < ovrEye_Count; eyeIdx++)
if (!eyeBuffers[eyeIdx].Create(hmdSession, w, h)) // this function's code is provided above
{
ovr_GetLastErrorInfo(&err);
log_error(err.ErrorString); // "BindFlags not supported for OpenGL applications."
}


So according to the error message, SDK thinks that I am assigned something to desc.BindFlags, while I am not. I tried to directly assign ovrTextureBind_None value to it (which is just zero), but still no success. I traced all variable values in debugger, they are the same as is the OculusRoomTiny (GL) sample. The only difference in my code that I can see is that I am using GLEW library to handle OpenGL extensions, while sample uses OVR::GLE. It initializes it immediately after wglMakeCurrent():

    OVR::GLEContext::SetCurrentContext(&GLEContext);
GLEContext.Init();

Can this be the cause? But I don't want to switch to Oculus' extensions library. My project is not Oculus-exclusive, it supports Vive and non-VR modes as well. If it is a bug inside libovr, I request Oculus team to fix it!
14 REPLIES 14

drkaii
Explorer
Hi

This is for an amazing simulator called space engine, Oculus please prioritise! I can confirm that the issue happens with the CV1, so it's nothing to do with the fact he is using the DK2

malfet
Honored Guest
Can you please add the following before ovr_CreateTextureSwapChainGL() call and post results here:
{
char str[256];
sprintf_s(str, "sizeof(void*)=%u sizeof(desc)=%u\n", (unsigned)sizeof(void*), (unsigned)sizeof(desc));
MessageBoxA(NULL, str, "Info", 0);
}

SpaceEngineer
Explorer
sizeof(void*)=4 sizeof(desc)=37

I'll try to make a separate exe with the problem isolated.

SpaceEngineer
Explorer
Oh lol, malfet, you inspired me on a small hack, and it works!

#pragma pack (push, 1)

// make it 64 bytes long
struct ovrHack
{
ovrTextureSwapChainDesc desc;
char padding[27];
};

#pragma pack (pop)
    ovrHack hack;
memset(&hack, 0, sizeof(hack));

lprint("%u", sizeof(hack)); // reports 64

hack.desc.Type = ovrTexture_2D;
hack.desc.ArraySize = 1;
hack.desc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
hack.desc.Width = w;
hack.desc.Height = h;
hack.desc.MipLevels = isHiQuality ? 3 : 1;
hack.desc.SampleCount = 1;
hack.desc.StaticImage = ovrFalse;

ovrResult res = ovr_CreateTextureSwapChainGL(session, &hack.desc, &swapTextures);
return (res == ovrSuccess); // SUCCESS!!!
So there is some alignment/padding problem? Can I fix it by modifying libovr headers, or have to live with this hack?

SpaceEngineer
Explorer
Ok, I made a separate project with only OpenGL and Oculus initialization, but can't reproduce this bug there.

Can this bug be caused by the fact that I am using a custom build of libOVR with 
_HAS_ITERATOR_DEBUGGING set to 0? I was forced to do this because of a linker error. I added this to OVR_CAPI.h and rebuild the .lib:

#if defined(_MSC_VER) && _MSC_VER <= 1900
#define _HAS_ITERATOR_DEBUGGING 0 // Disable run-time checking of std iterators
#endif

malfet
Honored Guest
Oculus Runtime expects offset of all members of ovrTextureSwapChainDesc structure to be 4 bytes aligned (i.e. offsetof(ovrTextureSwapChainDesc, BindFlags) should be 36). Which is not the case, if  you compile your project with the custom struct member alignment option or use "pragma pack(1)" before including "OVR_CAPI.h".

Alternatively, you can remedy the situation by adding the padding after ovrTextureSwapChainDesc.StaticImage or by using __declspec(align(4)) option to ensure that  ovrTextureSwapChainDesc.[Misc|Bind]Flags are 4 bytes aligned.

SpaceEngineer
Explorer
Yes, indeed, #pragma pack (show) returns 1, if being placed before including of libovr headers. This is strange, because I don't using /Zp (it is default), and have exactly the same amount of #pragma pushes and #pragma pops.

EDIT: lol, I found weird line in one of my headers:
#pragma pack (push, 1)
...
#pragma pack (pop, 1)
Be careful with copy-pasting!

Shouldn't ovr headers have their own #pragma pack options inside, to avoid such issues?
Or, alternatively, you may consider to re-arrange structures, by moving smaller members to the end. In the ovrTextureSwapChainDesc_ sctructure that is 1-byte-long ovrBool StaticImage member that destroys alignment in my case.

Anyway, thanks for the help!

FOKSlab
Explorer
HI,

I encounter the same kind of issue but no way to make "ovr_CreateTextureSwapChainGL" succeed even following the smart advises in this thread.

I checked the BindFlags offset and it is OK (36). But as soon as I set the MiscFlags & BindFlags (0 for both of them) in the swap chain descriptor, an access violation exception is raised. If I do not set them it does not generate the access violation but swapchain is not created, here is the output in this case:

 {INFO}    [Kernel:Default] [CAPI] LibOVR module is located at C:\Program Files\Oculus\Support\oculus-runtime\LibOVRRT32_1.dll
{DEBUG}   [Client] Connected to the server running version (prod = 1).1.24.0(build = 547103) feature version = 0. Client runs version (prod = 1).1.24.0(build = 0) feature version = 0
{DEBUG}   [Kernel:Default] [HMDState] Using default profile default
{INFO}    [Kernel:Default] IAD changed to 64.0mm
{DEBUG}   [SharedMemory] Creating factory
{!ERROR!} [Kernel:Error] OVR Error:
  Code: -1005 -- ovrError_InvalidParameter
  Description: BindFlags not supported for OpenGL applications.

I am sure Open GL context is OK since I can create textures, shaders, PBO, VAO/VBO before calling libOVR functions.
Where does the issue come from (since it seems not to come from the memory alignment) ? Have you got an idea how I can fix that ?

--- Using Visual Studio 2017 (conversion from Visual Studio 2015 solution and libOVR generated from VS2017) the sample project "OculusRoomTiny(GL)" raises the same exception on ovr_CreateTextureSwapChainGL. No issue using the sample on Visual Studio 2013 (but unfortunatelly I have to use Visual Studio 2017 with my code since I use nanogui).



SpaceEngineer
Explorer
It seems latest update to Oculus runtime (1.29) broke things again. My engine again fails to create texture swap with ovr_CreateTextureSwapChainGL(), the error code now is ovrError_ServiceError (-1006). I thought simple rebuild with the new SDK 1.29 will help, but I didn't found it on the download page. Version 1.26 is the latest:
https://developer.oculus.com/downloads/package/oculus-sdk-for-windows/1.26.0/

ovrTextureSwapChainDesc structure size (40) and BindFlags offset (36) seems correct. Wow, I see you added __declspec(align(4)) to the last two fields 🙂

Also, ovr_GetLastErrorInfo() with error code -1006 returns string <unknown>, instead of something like "ovr service error". Is this intentional?