-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfaulting in FFI #91
Comments
Can confirm, caused by #90. Keeping the pub struct Library {
raw: ffi::FT_Library,
// Hold onto this because FT_Library references it internally.
_memory: Box<ffi::FT_MemoryRec>,
}
impl Library {
pub fn init() -> FtResult<Library> {
let memory = box ffi::FT_MemoryRec {
user: 0 as *mut c_void,
alloc: alloc_library,
free: free_library,
realloc: realloc_library,
};
unsafe {
let mut raw = std::ptr::null_mut();
let err = ffi::FT_New_Library(&*memory, &mut raw);
if err == ffi::FT_Err_Ok {
ffi::FT_Add_Default_Modules(raw);
Ok(Library {
raw: raw,
_memory: memory,
})
} else {
Err(FromPrimitive::from_i32(err).unwrap())
}
}
}
// ...
} It's segfaulting in other places still so I'm calling this solution a work in progress. |
Another backtrace (with
Relevant function: FT_EXPORT_DEF( FT_Error )
FT_Done_Face( FT_Face face )
{
FT_Error error;
FT_Driver driver;
FT_Memory memory;
FT_ListNode node;
error = FT_ERR( Invalid_Face_Handle );
if ( face && face->driver )
{
face->internal->refcount--;
if ( face->internal->refcount > 0 )
error = FT_Err_Ok;
else
{
driver = face->driver;
memory = driver->root.memory;
/* find face in driver's list */
node = FT_List_Find( &driver->faces_list, face );
if ( node )
{
/* remove face object from the driver's list */
FT_List_Remove( &driver->faces_list, node );
FT_FREE( node );
/* now destroy the object proper */
destroy_face( memory, face, driver );
error = FT_Err_Ok;
}
}
}
return error;
} Not sure what might be segfaulting here. I wish I had debug symbols. Maybe I'll work on a debug build of Freetype tonight. |
Got Freetype with debug symbols! Things are getting interesting. Backtrace of previous comment, plus some debugging:
I think |
Nice work @cybergeek94! 👍 |
I tried the Box solution and continued see crashing as you mentioned. Rc seems to work for me though: use std::rc::Rc;
//...
pub struct Library {
raw: ffi::FT_Library,
_memory: Rc<ffi::FT_MemoryRec>,
}
impl Library {
pub fn init() -> FtResult<Library> {
let memory = Rc::new(ffi::FT_MemoryRec {
user: 0 as *mut c_void,
alloc: alloc_library,
free: free_library,
realloc: realloc_library,
});
unsafe {
let mut raw = std::ptr::null_mut();
let err = ffi::FT_New_Library(memory.deref(), &mut raw);
if err == ffi::FT_Err_Ok {
ffi::FT_Add_Default_Modules(raw);
Ok(Library {
raw: raw,
_memory: memory,
})
} else {
Err(FromPrimitive::from_i32(err).unwrap())
}
}
}
// ... |
@jakerr Looks like you've got it! Still having trouble with You want to issue a PR or should I? |
Still having trouble in a multithreaded context, even though I created
I have no idea what to make of this. The function pointers appear to be initialized properly, but when I try to call them, they segfault:
|
I fixed it. It was easy. In struct FT_MemoryRec {
//...
}
unsafe impl Sync for FT_MemoryRec {} Then revert #90. No more segfaults, even in threaded contexts. Alternately, we could avoid dealing with |
@cybergeek94 Thanks for working on this! Reverted with #92 |
I downloaded Freetype's source to get the body of the relevant function (since there doesn't seem to be a debug symbols package available in the Ubuntu/Mint repos ¯_(ツ)_/¯ ):
The only place a segfault looks possible is the virtual call
memory->alloc()
which I think would segfault ifmemory
was null, correct?I can't figure out how to configure a debug build for Freetype or else I'd have tried to debug this further. I mean, I can configure it, but the
./configure
script is giving me weird errors.Is this possibly related to #90?
The text was updated successfully, but these errors were encountered: