Fix bugs in HW renderer found by Coverity scan
Merge pull request #1230 from dorkster/coverity

Fix bugs in HW renderer found by Coverity scan