Skip to content

Commit

Permalink
buffers somehow not working correctly and crashing findCode, removed
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcehunter committed Aug 10, 2018
1 parent 64e6ce0 commit b9b5548
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ NAN_MODULE_INIT(Image::Init)
Nan::SetAccessor(ctorInst, Nan::New("width").ToLocalChecked(), GetWidth);
Nan::SetAccessor(ctorInst, Nan::New("height").ToLocalChecked(), GetHeight);
Nan::SetAccessor(ctorInst, Nan::New("depth").ToLocalChecked(), GetDepth);
Nan::SetAccessor(ctorInst, Nan::New("resolution").ToLocalChecked(), GetResolution, SetResolution);

Nan::SetPrototypeMethod(ctor, "invert", Invert);
Nan::SetPrototypeMethod(ctor, "or", Or);
Expand Down
17 changes: 4 additions & 13 deletions src/zxing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PixSource : public zxing::LuminanceSource
};

PixSource::PixSource(Pix* pix, bool take)
: LuminanceSource(pix ? pix->w : 0, pix ? pix->h : 0)
: LuminanceSource(pix != NULL ? pix->w : 0, pix != NULL ? pix->h : 0)
{
if (take) {
assert(pix->d == 8);
Expand Down Expand Up @@ -187,11 +187,10 @@ NAN_SETTER(ZXing::SetImage)
{
ZXing* obj = Nan::ObjectWrap::Unwrap<ZXing>(info.This());
if (Image::HasInstance(value) || value->IsNull()) {
if (!obj->image_.IsEmpty()) {
obj->image_.Reset();
}
if (!value->IsNull()) {
obj->image_.Reset(value->ToObject());
} else if (!obj->image_.IsEmpty()) {
obj->image_.Reset();
}
} else {
Nan::ThrowTypeError("value must be of type Image");
Expand Down Expand Up @@ -261,15 +260,7 @@ NAN_METHOD(ZXing::FindCode)
object->Set(Nan::New("type").ToLocalChecked(),
Nan::New<String>(zxing::BarcodeFormat::barcodeFormatNames[result->getBarcodeFormat()]).ToLocalChecked());
object->Set(Nan::New("data").ToLocalChecked(),
Nan::New<String>(resultStr.c_str()).ToLocalChecked());
if (result->getRawBytes() != NULL) {
std::vector<char> resultRawBytes = (*(result->getRawBytes())).values();
object->Set(Nan::New("buffer").ToLocalChecked(),
Nan::NewBuffer((char*)resultRawBytes.data(), resultRawBytes.size()).ToLocalChecked());
} else {
object->Set(Nan::New("buffer").ToLocalChecked(),
Nan::NewBuffer(0).ToLocalChecked());
}
Nan::New<String>(resultStr).ToLocalChecked());
Local<Array> points = Nan::New<Array>();
auto strX = Nan::New("x").ToLocalChecked();
auto strY = Nan::New("y").ToLocalChecked();
Expand Down

0 comments on commit b9b5548

Please sign in to comment.