Skip to content

Commit 24b6d55

Browse files
m0dBm0dB
authored andcommitted
avoid rendering on images with 0 or negative width or height
1 parent 17883f9 commit 24b6d55

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎src/waveform/renderers/allshader/digitsrenderer.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ float allshader::DigitsRenderer::height() const {
6969

7070
void allshader::DigitsRenderer::updateTexture(
7171
float fontPointSize, float maxHeight, float devicePixelRatio) {
72+
if (std::lround(maxHeight * devicePixelRatio) <= 0) {
73+
return;
74+
}
75+
7276
if (fontPointSize == m_fontPointSize && maxHeight == m_maxHeight) {
7377
return;
7478
}

‎src/waveform/renderers/allshader/waveformrendermark.cpp‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,14 @@ void allshader::WaveformRenderMark::updatePlayPosMarkTexture() {
403403
imgwidth = 11.f;
404404
imgheight = height;
405405

406-
QImage image(static_cast<int>(imgwidth * devicePixelRatio),
407-
static_cast<int>(imgheight * devicePixelRatio),
408-
QImage::Format_ARGB32_Premultiplied);
406+
const QSize size{static_cast<int>(std::lround(imgwidth * devicePixelRatio)),
407+
static_cast<int>(std::lround(imgheight * devicePixelRatio))};
408+
409+
if (size.width() <= 0 || size.height() <= 0) {
410+
return;
411+
}
412+
413+
QImage image(size, QImage::Format_ARGB32_Premultiplied);
409414
image.setDevicePixelRatio(devicePixelRatio);
410415
image.fill(QColor(0, 0, 0, 0).rgba());
411416

‎src/waveform/renderers/waveformmark.cpp‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ struct MarkerGeometry {
311311
}
312312
}
313313
QSize getImageSize(float devicePixelRatio) const {
314-
return QSize{static_cast<int>(m_imageSize.width() * devicePixelRatio),
315-
static_cast<int>(m_imageSize.height() * devicePixelRatio)};
314+
return QSize{static_cast<int>(std::lround(m_imageSize.width() * devicePixelRatio)),
315+
static_cast<int>(std::lround(m_imageSize.height() * devicePixelRatio))};
316316
}
317317
};
318318

@@ -357,9 +357,14 @@ QImage WaveformMark::generateImage(float devicePixelRatio) {
357357

358358
m_label.setAreaRect(markerGeometry.m_labelRect);
359359

360+
const QSize size{markerGeometry.getImageSize(devicePixelRatio)};
361+
362+
if (size.width() <= 0 || size.height() <= 0) {
363+
return QImage{};
364+
}
365+
360366
// Create the image
361-
QImage image{markerGeometry.getImageSize(devicePixelRatio),
362-
QImage::Format_ARGB32_Premultiplied};
367+
QImage image{size, QImage::Format_ARGB32_Premultiplied};
363368
image.setDevicePixelRatio(devicePixelRatio);
364369

365370
// Fill with transparent pixels

0 commit comments

Comments
 (0)