Skip to content

Commit

Permalink
Add assertions into blit(), discover an off-by-one bug and fix that bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
vkoskiv committed Jan 17, 2020
1 parent 4dcc12e commit ab75898
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/datatypes/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#include "texture.h"
#include "color.h"
#include "../utils/logging.h"
#include "../utils/assert.h"

//General-purpose blit function
void blit(struct texture *t, struct color c, unsigned x, unsigned y) {
if ((x > t->width-1) || y < 0) return;
if ((y > t->height-1) || y < 0) return;

ASSERT(x < t->width); ASSERT(y < t->height);
ASSERT(x >= 0); ASSERT(y >= 0);
if (t->precision == char_p) {
t->byte_data[(x + (t->height - (y + 1)) * t->width) * t->channels + 0] = (unsigned char)min(c.red * 255.0, 255.0);
t->byte_data[(x + (t->height - (y + 1)) * t->width) * t->channels + 1] = (unsigned char)min(c.green * 255.0, 255.0);
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ void *renderThread(void *arg) {

while (tile.completedSamples < r->prefs.sampleCount+1 && r->state.isRendering) {
startTimer(&timer);
for (int y = (int)tile.end.y; y > (int)tile.begin.y; y--) {
for (int x = (int)tile.begin.x; x < (int)tile.end.x; x++) {
for (int y = tile.end.y - 1; y > tile.begin.y - 1; --y) {
for (int x = tile.begin.x; x < tile.end.x; ++x) {
if (r->state.renderAborted) return 0;
uint64_t pixIdx = y * image->width + x;
uint64_t uniqueIdx = pixIdx * r->prefs.sampleCount + tile.completedSamples;
Expand Down

0 comments on commit ab75898

Please sign in to comment.