Fix segfault in VideoSystem::display_name

Closes #650
This commit is contained in:
Cobrand
2017-05-02 09:03:02 +02:00
parent cddc9a9fa1
commit f1eea15e00
+10 -2
View File
@@ -525,10 +525,18 @@ impl VideoSubsystem {
}
}
pub fn display_name(&self, display_index: i32) -> String {
/// Get the name of the display at the index `display_name`.
///
/// Will return an error if the index is out of bounds or if SDL experienced a failure; inspect
/// the returned string for further info.
pub fn display_name(&self, display_index: i32) -> Result<String, String> {
unsafe {
let display = ll::SDL_GetDisplayName(display_index as c_int);
CStr::from_ptr(display as *const _).to_str().unwrap().to_owned()
if display.is_null() {
Err(get_error())
} else {
Ok(CStr::from_ptr(display as *const _).to_str().unwrap().to_owned())
}
}
}