Skip to content

Commit

Permalink
fix batch issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aydenp committed Jun 23, 2018
1 parent 544b1f2 commit f9c8c48
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion util/PaintingManager.js
Expand Up @@ -18,6 +18,7 @@ function PaintingManager(app) {
firstGenerateAfterLoad: false,
pixelsToPaint: [],
pixelsToPreserve: null,
isGenerating: false,

getStartingImage: function() {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -74,8 +75,8 @@ function PaintingManager(app) {
clearInterval(progressUpdater);
app.logger.info("Startup", `Loaded total ${count.toLocaleString()} pixel${count == 1 ? "" : "s"} pixels from database. Applying to image...`);
if (this.pixelsToPreserve) this.pixelsToPreserve.forEach((data) => batch.setPixel(data.x, data.y, data.colour));
this.pixelsToPreserve = null;
batch.exec((err, image) => {
this.pixelsToPreserve = null;
if (err) return reject(err);
app.logger.info("Startup", `Applied pixels to image. Serving image...`);
serveImage(image);
Expand All @@ -102,6 +103,8 @@ function PaintingManager(app) {
generateOutputImage: function(skipImmediateCache = false) {
var a = this;
return new Promise((resolve, reject) => {
if (a.isGenerating) return reject();
a.isGenerating = true;
this.waitingForImages.push((err, buffer) => {
if (err) return reject(err);
resolve(buffer);
Expand All @@ -115,6 +118,7 @@ function PaintingManager(app) {
this.pixelsToPaint = [];
this.imageBatch.toBuffer("png", { compression: "fast", transparency: false }, (err, buffer) => {
a.outputImage = buffer;
a.isGenerating = false;
if (!err && !skipImmediateCache) {
fs.writeFile(temporaryCachedImagePath, buffer, (err) => {
if (err) return app.logger.error("Painting Manager", "Couldn't save cached board image, got error:", err);
Expand Down

0 comments on commit f9c8c48

Please sign in to comment.