瀏覽代碼

add permission error message and fix opengl example (#155)

Christoph Haag 7 年之前
父節點
當前提交
586ef18412
共有 2 個文件被更改,包括 5 次插入5 次删除
  1. 4 5
      examples/opengl/main.c
  2. 1 0
      src/openhmd.c

+ 4 - 5
examples/opengl/main.c

@@ -131,6 +131,10 @@ int main(int argc, char** argv)
 	ohmd_device_settings_seti(settings, OHMD_IDS_AUTOMATIC_UPDATE, &auto_update);
 
 	ohmd_device* hmd = ohmd_list_open_device_s(ctx, 0, settings);
+	if(!hmd){
+		printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx));
+		return 1;
+	}
 	ohmd_device_geti(hmd, OHMD_SCREEN_HORIZONTAL_RESOLUTION, &hmd_w);
 	ohmd_device_geti(hmd, OHMD_SCREEN_VERTICAL_RESOLUTION, &hmd_h);
 	float ipd;
@@ -160,11 +164,6 @@ int main(int argc, char** argv)
 
 	ohmd_device_settings_destroy(settings);
 
-	if(!hmd){
-		printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx));
-		return 1;
-	}
-
 	gl_ctx gl;
 	init_gl(&gl, hmd_w, hmd_h);
 

+ 1 - 0
src/openhmd.c

@@ -210,6 +210,7 @@ ohmd_device* OHMD_APIENTRY ohmd_list_open_device_s(ohmd_context* ctx, int index,
 		ohmd_device* device = driver->open_device(driver, desc);
 
 		if (device == NULL) {
+			ohmd_set_error(ctx, "Could not open device with index: %d, check device permissions?", index);
 			ohmd_unlock_mutex(ctx->update_mutex);
 			return NULL;
 		}