Permalink
Browse files

reference count Grid objects in use by GridView objects to avoid poss…

…ible scope issues resulting in segfaults when v8 garbage collects - closes #110, refs #89
  • Loading branch information...
Dane Springmeyer
Dane Springmeyer committed Jul 12, 2012
1 parent eeb2ccc commit f06ecd098870adf1b05c790c599a3c8bfe44651e
Showing with 15 additions and 8 deletions.
  1. +1 −1 src/mapnik_grid.cpp
  2. +9 −5 src/mapnik_grid_view.cpp
  3. +5 −2 src/mapnik_grid_view.hpp
View
@@ -214,7 +214,7 @@ Handle<Value> Grid::view(const Arguments& args)
unsigned h = args[3]->IntegerValue();
Grid* g = ObjectWrap::Unwrap<Grid>(args.This());
- return scope.Close(GridView::New(g->get(),x,y,w,h));
+ return scope.Close(GridView::New(g,x,y,w,h));
}
View
@@ -37,12 +37,16 @@ void GridView::Initialize(Handle<Object> target) {
}
-GridView::GridView(grid_view_ptr gp) :
+GridView::GridView(Grid * JSGrid) :
ObjectWrap(),
- this_(gp) {}
+ this_(),
+ JSGrid_(JSGrid) {
+ JSGrid_->_ref();
+ }
GridView::~GridView()
{
+ JSGrid_->_unref();
}
Handle<Value> GridView::New(const Arguments& args)
@@ -65,16 +69,16 @@ Handle<Value> GridView::New(const Arguments& args)
return Undefined();
}
-Handle<Value> GridView::New(boost::shared_ptr<mapnik::grid> grid_ptr,
+Handle<Value> GridView::New(Grid * JSGrid,
unsigned x,
unsigned y,
unsigned w,
unsigned h
)
{
HandleScope scope;
- grid_view_ptr gb_ptr = boost::make_shared<mapnik::grid_view>(grid_ptr->get_view(x,y,w,h));
- GridView* gv = new GridView(gb_ptr);
+ GridView* gv = new GridView(JSGrid);
+ gv->this_ = boost::make_shared<mapnik::grid_view>(JSGrid->get()->get_view(x,y,w,h));
Handle<Value> ext = External::New(gv);
Handle<Object> obj = constructor->GetFunction()->NewInstance(1, &ext);
return scope.Close(obj);
View
@@ -8,6 +8,8 @@
#include <mapnik/grid/grid.hpp>
#include <boost/shared_ptr.hpp>
+#include "mapnik_grid.hpp"
+
using namespace v8;
using namespace node;
@@ -18,7 +20,7 @@ class GridView: 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::grid> grid_ptr,
+ static Handle<Value> New(Grid * JSGrid,
unsigned x,unsigned y, unsigned w, unsigned h);
static Handle<Value> encodeSync(const Arguments &args);
@@ -31,12 +33,13 @@ class GridView: public node::ObjectWrap {
static Handle<Value> isSolid(const Arguments &args);
static Handle<Value> getPixel(const Arguments &args);
- GridView(grid_view_ptr gp);
+ GridView(Grid * JSGrid);
inline grid_view_ptr get() { return this_; }
private:
~GridView();
grid_view_ptr this_;
+ Grid * JSGrid_;
};
#endif

0 comments on commit f06ecd0

Please sign in to comment.