examples: Use c_char for pointer to raw string (#521)

On platforms like Android strings use `u8` as character-type instead of
`i8` - using the appropriate `c_char` type hides this discrepancy and
allows the examples to compile for all platforms.
This commit is contained in:
Marijn Suijten 2021-12-21 20:42:47 +01:00 committed by GitHub
parent a7d5c49029
commit 90960efded
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- examples: Use `c_char` for pointer to raw string (#521)
- Device extension `khr::PipelineExecutableProperties` and `khr::TimelineSemaphore` now expose `fn device()` instead of `fn instance()` (#499) - Device extension `khr::PipelineExecutableProperties` and `khr::TimelineSemaphore` now expose `fn device()` instead of `fn instance()` (#499)
- Changed `khr::PipelineExecutableProperties::new()` and `khr::TimelineSemaphore::new()` to take `instance` and `device` as arguments (#499) - Changed `khr::PipelineExecutableProperties::new()` and `khr::TimelineSemaphore::new()` to take `instance` and `device` as arguments (#499)

View file

@ -13,6 +13,7 @@ use std::cell::RefCell;
use std::default::Default; use std::default::Default;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::ops::Drop; use std::ops::Drop;
use std::os::raw::c_char;
use winit::{ use winit::{
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
@ -219,8 +220,10 @@ impl ExampleBase {
let entry = Entry::new(); let entry = Entry::new();
let app_name = CString::new("VulkanTriangle").unwrap(); let app_name = CString::new("VulkanTriangle").unwrap();
let layer_names = [CString::new("VK_LAYER_KHRONOS_validation").unwrap()]; let layer_names = [CStr::from_bytes_with_nul_unchecked(
let layers_names_raw: Vec<*const i8> = layer_names b"VK_LAYER_KHRONOS_validation\0",
)];
let layers_names_raw: Vec<*const c_char> = layer_names
.iter() .iter()
.map(|raw_name| raw_name.as_ptr()) .map(|raw_name| raw_name.as_ptr())
.collect(); .collect();