Skip to content

Commit

Permalink
Provide default templateImage width/height if image cannot be loaded,…
Browse files Browse the repository at this point in the history
… and avoid dividing by 0 when using getWidth/getHeight on an image that is not loaded
  • Loading branch information
paulreimer committed Jan 3, 1970
1 parent eaf9492 commit 74ba293
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/NanoKontrol2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ NanoKontrol2::setup()

// Default Draw Size
float controllerWidth = 500;
float controllerAspect = ((float)templateImage.getHeight() /
(float)templateImage.getWidth());
float controllerAspect;
if (templateImage.isAllocated())
controllerAspect = ((float)templateImage.getHeight() /
(float)templateImage.getWidth());
else
controllerAspect = ((float)300 /
(float)1190); // stock image size

drawRect.set(0, 0, controllerWidth, controllerWidth*controllerAspect);

ofVec2f mixerChannelOffset(356, 23);
Expand Down Expand Up @@ -150,8 +156,9 @@ NanoKontrol2::draw()
ofPushMatrix();
{
ofTranslate(drawRect.x, drawRect.y);
ofScale(drawRect.width/templateImage.getWidth(),
drawRect.height/templateImage.getHeight());
if (drawRect.width > 0 && drawRect.height > 0)
ofScale(drawRect.width/templateImage.getWidth(),
drawRect.height/templateImage.getHeight());

// Draw special buttons
{
Expand Down

0 comments on commit 74ba293

Please sign in to comment.