Skip to content

Commit

Permalink
fix: bitmap destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlewind committed Jan 18, 2021
1 parent 8d5ded6 commit b138da2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions skia-c/skia_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,4 +763,9 @@ extern "C"
auto bitmap = reinterpret_cast<SkBitmap *>(c_bitmap);
return bitmap->height();
}

void skiac_bitmap_destroy(skiac_bitmap *c_bitmap)
{
delete BITMAP_CAST;
}
}
1 change: 1 addition & 0 deletions skia-c/skia_c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ extern "C"
skiac_bitmap *skiac_bitmap_make_from_buffer(uint8_t *ptr, size_t size);
uint32_t skiac_bitmap_get_width(skiac_bitmap *c_bitmap);
uint32_t skiac_bitmap_get_height(skiac_bitmap *c_bitmap);
void skiac_bitmap_destroy(skiac_bitmap *c_bitmap);
}

#endif // SKIA_CAPI_H
10 changes: 10 additions & 0 deletions src/sk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ mod ffi {
pub fn skiac_bitmap_get_width(c_bitmap: *mut skiac_bitmap) -> u32;

pub fn skiac_bitmap_get_height(c_bitmap: *mut skiac_bitmap) -> u32;

pub fn skiac_bitmap_destroy(c_bitmap: *mut skiac_bitmap);
}
}

Expand Down Expand Up @@ -2083,6 +2085,14 @@ impl Bitmap {
}
}

impl Drop for Bitmap {
fn drop(&mut self) {
unsafe {
ffi::skiac_bitmap_destroy(self.bitmap);
}
}
}

#[inline(always)]
fn radians_to_degrees(rad: f32) -> f32 {
(rad / PI) * 180.0
Expand Down

0 comments on commit b138da2

Please sign in to comment.