mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
prevent panics on core load failure
This commit is contained in:
parent
7ab17d7a4e
commit
eb538b4536
|
@ -31,6 +31,7 @@ struct MGBA* new_runner(char* filename) {
|
||||||
struct mCore* core = mCoreFind(mgba->filename);
|
struct mCore* core = mCoreFind(mgba->filename);
|
||||||
if (!core) {
|
if (!core) {
|
||||||
printf("failed to find core\n");
|
printf("failed to find core\n");
|
||||||
|
free(mgba);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ fn test_file(file_to_run: &str) -> Status {
|
||||||
let mut finished = Status::Running;
|
let mut finished = Status::Running;
|
||||||
let debug_reader_mutex = Regex::new(r"(?s)^\[(.*)\] GBA Debug: (.*)$").unwrap();
|
let debug_reader_mutex = Regex::new(r"(?s)^\[(.*)\] GBA Debug: (.*)$").unwrap();
|
||||||
|
|
||||||
let mut mgba = runner::MGBA::new(file_to_run);
|
let mut mgba = runner::MGBA::new(file_to_run).unwrap();
|
||||||
let video_buffer = mgba.get_video_buffer();
|
let video_buffer = mgba.get_video_buffer();
|
||||||
|
|
||||||
mgba.set_logger(|message| {
|
mgba.set_logger(|message| {
|
||||||
|
|
|
@ -35,10 +35,13 @@ impl VideoBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MGBA {
|
impl MGBA {
|
||||||
pub fn new(filename: &str) -> Self {
|
pub fn new(filename: &str) -> Result<Self, anyhow::Error> {
|
||||||
let c_str = CString::new(filename).expect("should be able to make cstring from filename");
|
let c_str = CString::new(filename).expect("should be able to make cstring from filename");
|
||||||
MGBA {
|
let mgba = unsafe { bindings::new_runner(c_str.as_ptr() as *mut i8) };
|
||||||
mgba: unsafe { bindings::new_runner(c_str.as_ptr() as *mut i8) },
|
if mgba.is_null() {
|
||||||
|
Err(anyhow::anyhow!("could not create core"))
|
||||||
|
} else {
|
||||||
|
Ok(MGBA { mgba })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue