fix illegal instruction during handle ptr creation in release mode
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{marker::Unsize, mem::MaybeUninit, ops::CoerceUnsized, sync::mpsc::Sender};
|
||||
use std::{marker::Unsize, ops::CoerceUnsized, sync::mpsc::Sender};
|
||||
|
||||
use crate::{
|
||||
HasUi, Widget,
|
||||
@@ -44,7 +44,7 @@ impl<W: ?Sized> WidgetHandle<W> {
|
||||
id,
|
||||
counter: RefCounter::new(),
|
||||
send,
|
||||
ty: unsafe { MaybeUninit::zeroed().assume_init() },
|
||||
ty: null_ptr(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,10 +69,7 @@ impl<W: ?Sized> WidgetHandle<W> {
|
||||
|
||||
impl<W: ?Sized> WidgetRef<W> {
|
||||
pub(crate) fn new(id: WidgetId) -> Self {
|
||||
Self {
|
||||
id,
|
||||
ty: unsafe { MaybeUninit::zeroed().assume_init() },
|
||||
}
|
||||
Self { id, ty: null_ptr() }
|
||||
}
|
||||
|
||||
pub fn id(&self) -> WidgetId {
|
||||
@@ -163,3 +160,12 @@ impl<'a, W: Widget + 'a, State: HasUi> FnOnce<(&'a mut State,)> for WidgetRef<W>
|
||||
&mut args.0.ui_mut()[self]
|
||||
}
|
||||
}
|
||||
|
||||
fn null_ptr<W: ?Sized>() -> *const W {
|
||||
if size_of::<&W>() == size_of::<*const dyn Widget>() {
|
||||
let w: *const dyn Widget = &();
|
||||
unsafe { std::mem::transmute_copy(&w) }
|
||||
} else {
|
||||
unsafe { std::mem::transmute_copy(&[0usize; 1]) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user