Permalink
Browse files

reference count Image objects in use by ImageView objects to avoid po…

…ssible scope issues resulting in segfaults when v8 garbage collects - closes #89, refs #110
  • Loading branch information...
1 parent f06ecd0 commit a36d45e94b9cc4b09f918b3c4adc3a18aa5ce2e9 Dane Springmeyer committed Jul 12, 2012
Showing with 15 additions and 8 deletions.
  1. +1 −1 src/mapnik_image.cpp
  2. +9 −5 src/mapnik_image_view.cpp
  3. +5 −2 src/mapnik_image_view.hpp
View
@@ -476,7 +476,7 @@ Handle<Value> Image::view(const Arguments& args)
unsigned h = args[3]->IntegerValue();
Image* im = ObjectWrap::Unwrap<Image>(args.This());
- return scope.Close(ImageView::New(im->get(),x,y,w,h));
+ return scope.Close(ImageView::New(im,x,y,w,h));
}
Handle<Value> Image::save(const Arguments& args)
View
@@ -40,12 +40,16 @@ void ImageView::Initialize(Handle<Object> target) {
}
-ImageView::ImageView(image_view_ptr this_) :
+ImageView::ImageView(Image * JSImage) :
ObjectWrap(),
- this_(this_) {}
+ this_(),
+ JSImage_(JSImage) {
+ JSImage_->_ref();
+ }
ImageView::~ImageView()
{
+ JSImage_->_unref();
}
Handle<Value> ImageView::New(const Arguments& args)
@@ -68,16 +72,16 @@ Handle<Value> ImageView::New(const Arguments& args)
return Undefined();
}
-Handle<Value> ImageView::New(boost::shared_ptr<mapnik::image_32> image_ptr,
+Handle<Value> ImageView::New(Image * JSImage ,
unsigned x,
unsigned y,
unsigned w,
unsigned h
)
{
HandleScope scope;
- image_view_ptr iv_ptr = boost::make_shared<mapnik::image_view<mapnik::image_data_32> >(image_ptr->get_view(x,y,w,h));
- ImageView* imv = new ImageView(iv_ptr);
+ ImageView* imv = new ImageView(JSImage);
+ imv->this_ = boost::make_shared<mapnik::image_view<mapnik::image_data_32> >(JSImage->get()->get_view(x,y,w,h));
Handle<Value> ext = External::New(imv);
Handle<Object> obj = constructor->GetFunction()->NewInstance(1, &ext);
return scope.Close(obj);
@@ -9,6 +9,8 @@
#include <mapnik/graphics.hpp>
#include <boost/shared_ptr.hpp>
+#include "mapnik_image.hpp"
+
using namespace v8;
using namespace node;
@@ -19,7 +21,7 @@ class ImageView: public node::ObjectWrap {
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
- static Handle<Value> New(boost::shared_ptr<mapnik::image_32> image_ptr,
+ static Handle<Value> New(Image * JSImage,
unsigned x,unsigned y, unsigned w, unsigned h);
static Handle<Value> encodeSync(const Arguments &args);
@@ -35,12 +37,13 @@ class ImageView: public node::ObjectWrap {
static Handle<Value> isSolid(const Arguments &args);
static Handle<Value> getPixel(const Arguments &args);
- ImageView(image_view_ptr this_);
+ ImageView(Image * JSImage);
inline image_view_ptr get() { return this_; }
private:
~ImageView();
image_view_ptr this_;
+ Image * JSImage_;
};
#endif

0 comments on commit a36d45e

Please sign in to comment.