mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +01:00
script: check if the canvas is paintable before measuring text (#38664)
The `Canvas2dMsg::MeasureText` is dropped inside `send_canvas_2d_msg` if the canvas is not paintable, leading to a panic on the receiving end. Checking the paint-ability before sending the message prevents this panic, and if the canvas is not pain-table, a default text metrics is used. Testing: Manual testing of the minimal test case in the associated issue, and crash test added. Fixes: https://github.com/servo/servo/issues/36845 --------- Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
parent
cf866d12b4
commit
be5e7a982b
3 changed files with 29 additions and 8 deletions
|
@ -1427,13 +1427,21 @@ impl CanvasState {
|
|||
self.set_font(canvas, CanvasContextState::DEFAULT_FONT_STYLE.into());
|
||||
}
|
||||
|
||||
let (sender, receiver) = ipc::channel::<CanvasTextMetrics>().unwrap();
|
||||
self.send_canvas_2d_msg(Canvas2dMsg::MeasureText(
|
||||
text.into(),
|
||||
sender,
|
||||
self.state.borrow().text_options(),
|
||||
));
|
||||
let metrics = receiver.recv().unwrap();
|
||||
let metrics = {
|
||||
if !self.is_paintable() {
|
||||
CanvasTextMetrics::default()
|
||||
} else {
|
||||
let (sender, receiver) = ipc::channel::<CanvasTextMetrics>().unwrap();
|
||||
self.send_canvas_2d_msg(Canvas2dMsg::MeasureText(
|
||||
text.into(),
|
||||
sender,
|
||||
self.state.borrow().text_options(),
|
||||
));
|
||||
receiver
|
||||
.recv()
|
||||
.expect("Failed to receive response from canvas paint thread")
|
||||
}
|
||||
};
|
||||
|
||||
TextMetrics::new(
|
||||
global,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue