File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ const USE_BUILT_BINDINGS: &str = "PD_BUILD_BINDINGS_ONCE";
30
30
fn main ( ) {
31
31
println ! ( "cargo:rerun-if-env-changed={SDK_PATH_ENV_VAR}" ) ;
32
32
33
+ println ! ( "cargo::rustc-check-cfg=cfg(playdate)" ) ;
34
+ if matches ! ( Target :: from_env_target( ) , Ok ( Target :: Playdate ) ) {
35
+ println ! ( "cargo::rustc-cfg=playdate" )
36
+ }
37
+
33
38
let mut cfg = Cfg :: default ( ) ;
34
39
cfg. derive . default = feature_derive_default ( ) ;
35
40
cfg. derive . eq = feature_derive_eq ( ) ;
Original file line number Diff line number Diff line change @@ -70,10 +70,21 @@ pub extern "C" fn eventHandlerShim(api: *const ffi::PlaydateAPI,
70
70
-> core:: ffi:: c_int {
71
71
extern "Rust" {
72
72
fn event_handler ( api : * const ffi:: PlaydateAPI , event : ffi:: PDSystemEvent , arg : u32 ) -> EventLoopCtrl ;
73
+
74
+ #[ cfg( not( playdate) ) ]
75
+ // This is atomic in the `sys::proc::error`.
76
+ static END_WITH_ERR : core:: sync:: atomic:: AtomicBool ;
73
77
}
78
+
74
79
if let ffi:: PDSystemEvent :: kEventInit = event {
75
80
unsafe { API = api }
76
81
}
82
+
83
+ #[ cfg( not( playdate) ) ]
84
+ if unsafe { END_WITH_ERR . load ( core:: sync:: atomic:: Ordering :: Relaxed ) } {
85
+ return EventLoopCtrl :: Stop . into ( ) ;
86
+ }
87
+
77
88
unsafe { event_handler ( api, event, arg) } . into ( )
78
89
}
79
90
Original file line number Diff line number Diff line change @@ -12,6 +12,23 @@ pub fn abort() -> ! { core::intrinsics::abort() }
12
12
/// In case of missed [`crate::sys::API`] (doesn't set) uses [`abort`].
13
13
#[ track_caller]
14
14
pub fn error < S : AsRef < str > > ( text : S ) -> ! {
15
+ #[ cfg( not( playdate) ) ]
16
+ {
17
+ use core:: sync:: atomic:: AtomicBool ;
18
+ use core:: sync:: atomic:: Ordering ;
19
+
20
+ // This is unreachable on the device,
21
+ // `API.system.error` interrupts the execution.
22
+ // But simulator doesn't stops.
23
+ // So, instead of spin-loop just save the flag and use later in the event-handler.
24
+
25
+ #[ no_mangle]
26
+ static END_WITH_ERR : AtomicBool = AtomicBool :: new ( false ) ;
27
+
28
+ END_WITH_ERR . store ( true , Ordering :: Relaxed ) ;
29
+ }
30
+
31
+
15
32
if let Some ( f) = unsafe { ( * ( * crate :: sys:: API ) . system ) . error } {
16
33
// Casting fn->void to fn->!
17
34
// This ugly cast is safe because of `!` is a magic compile-time marker, not a type.
@@ -28,7 +45,4 @@ pub fn error<S: AsRef<str>>(text: S) -> ! {
28
45
// In case of `crate::sys::API` is missed (doesn't set) just abort the process.
29
46
abort ( )
30
47
}
31
- // This is unreachable or the device,
32
- // `API.system.error` interrupts the execution.
33
- // But simulator doesn't stops on `error`.
34
48
}
You can’t perform that action at this time.
0 commit comments