Fixed bug which would cause program to crash if there was no image associated with an overlay in windows build (see checkbox in sunLightExample)

This commit is contained in:
Bing Shearer 2015-07-09 14:20:10 -07:00
parent 25708678f6
commit 85f6fdb8cf

View file

@ -75,12 +75,13 @@ void ImageOverlay::render(RenderArgs* args) {
glm::vec2 topLeft(left, top);
glm::vec2 bottomRight(right, bottom);
float imageWidth = _texture->getWidth();
float imageHeight = _texture->getHeight();
// if for some reason our image is not over 0 width or height, don't attempt to render the image
if (_renderImage && imageWidth > 0 && imageHeight > 0) {
if (_renderImage) {
float imageWidth = _texture->getWidth();
float imageHeight = _texture->getHeight();
if (imageWidth > 0 && imageHeight > 0) {
QRect fromImage;
if (_wantClipFromImage) {
float scaleX = imageWidth / _texture->getOriginalWidth();
@ -90,7 +91,8 @@ void ImageOverlay::render(RenderArgs* args) {
fromImage.setY(scaleY * _fromImage.y());
fromImage.setWidth(scaleX * _fromImage.width());
fromImage.setHeight(scaleY * _fromImage.height());
} else {
}
else {
fromImage.setX(0);
fromImage.setY(0);
fromImage.setWidth(imageWidth);
@ -106,15 +108,16 @@ void ImageOverlay::render(RenderArgs* args) {
glm::vec2 texCoordBottomRight(x + w, y + h);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor);
} else {
}
else {
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, quadColor);
}
if (_renderImage) {
glDisable(GL_TEXTURE_2D);
}
}
}
void ImageOverlay::setProperties(const QScriptValue& properties) {
Overlay2D::setProperties(properties);