Merge pull request #1410 from mitchellh/macos-scale

apprt/embedded: do not allow NaN or small content scales
This commit is contained in:
Mitchell Hashimoto
2024-01-29 08:40:45 -08:00
committed by GitHub

View File

@ -653,9 +653,15 @@ pub const Surface = struct {
} }
pub fn updateContentScale(self: *Surface, x: f64, y: f64) void { pub fn updateContentScale(self: *Surface, x: f64, y: f64) void {
// We are an embedded API so the caller can send us all sorts of
// garbage. We want to make sure that the float values are valid
// and we don't want to support fractional scaling below 1.
const x_scaled = @max(1, if (std.math.isNan(x)) 1 else x);
const y_scaled = @max(1, if (std.math.isNan(y)) 1 else y);
self.content_scale = .{ self.content_scale = .{
.x = @floatCast(x), .x = @floatCast(x_scaled),
.y = @floatCast(y), .y = @floatCast(y_scaled),
}; };
self.core_surface.contentScaleCallback(self.content_scale) catch |err| { self.core_surface.contentScaleCallback(self.content_scale) catch |err| {