Commit 71bbef82 authored by twanvl's avatar twanvl

Fixed another smart pointer bug (assignment operator copied ref count);

Fixed symbol editor grid
parent 4ae62eec
...@@ -150,9 +150,9 @@ void SymbolControl::draw(DC& dc) { ...@@ -150,9 +150,9 @@ void SymbolControl::draw(DC& dc) {
// draw grid // draw grid
if (settings.symbol_grid) { if (settings.symbol_grid) {
wxSize s = dc.GetSize(); wxSize s = dc.GetSize();
int lines = settings.symbol_grid_size; double lines = settings.symbol_grid_size;
for (int i = 0 ; i <= lines ; ++i) { for (int i = 0 ; i <= lines ; ++i) {
int x = (int) rotation.trS(i/lines-0.0001); int x = floor(rotation.trS(i/lines-0.0001));
//dc.SetPen(Color(0, i%5 == 0 ? 64 : 31, 0)); //dc.SetPen(Color(0, i%5 == 0 ? 64 : 31, 0));
//dc.SetPen(Color(i%5 == 0 ? 64 : 31, 0, 0)); //dc.SetPen(Color(i%5 == 0 ? 64 : 31, 0, 0));
dc.SetLogicalFunction(wxAND); dc.SetLogicalFunction(wxAND);
......
...@@ -160,7 +160,15 @@ inline shared_ptr<T> new_shared9(const A0& a0, const A1& a1, const A2& a2, const ...@@ -160,7 +160,15 @@ inline shared_ptr<T> new_shared9(const A0& a0, const A1& a1, const A2& a2, const
template <typename T> class IntrusivePtrBase { template <typename T> class IntrusivePtrBase {
public: public:
inline IntrusivePtrBase() : ref_count(0) {} inline IntrusivePtrBase() : ref_count(0) {}
inline IntrusivePtrBase(const IntrusivePtrBase&) : ref_count(0) {} // don't copy construct the reference count! // don't copy construct the reference count!
inline IntrusivePtrBase(const IntrusivePtrBase&) : ref_count(0) {}
// don't assign the reference count!
inline void operator = (const IntrusivePtrBase&) { }
protected:
/// Delete this object, can be overloaded
inline void destroy() {
delete static_cast<T*>(this);
}
private: private:
AtomicInt ref_count; AtomicInt ref_count;
template <typename T> friend void intrusive_ptr_add_ref(IntrusivePtrBase*); template <typename T> friend void intrusive_ptr_add_ref(IntrusivePtrBase*);
...@@ -172,7 +180,7 @@ inline shared_ptr<T> new_shared9(const A0& a0, const A1& a1, const A2& a2, const ...@@ -172,7 +180,7 @@ inline shared_ptr<T> new_shared9(const A0& a0, const A1& a1, const A2& a2, const
} }
template <typename T> inline void intrusive_ptr_release(IntrusivePtrBase<T>* p) { template <typename T> inline void intrusive_ptr_release(IntrusivePtrBase<T>* p) {
if (--p->ref_count == 0) { if (--p->ref_count == 0) {
delete static_cast<T*>(p); static_cast<T*>(p)->destroy();
} }
} }
...@@ -187,32 +195,17 @@ inline shared_ptr<T> new_shared9(const A0& a0, const A1& a1, const A2& a2, const ...@@ -187,32 +195,17 @@ inline shared_ptr<T> new_shared9(const A0& a0, const A1& a1, const A2& a2, const
// ----------------------------------------------------------------------------- : Intrusive pointer base : with delete // ----------------------------------------------------------------------------- : Intrusive pointer base : with delete
/// Base class for objects wishing to use intrusive_ptrs, using a manual delete function /// Base class for objects wishing to use intrusive_ptrs, using a manual delete function
class IntrusivePtrBaseWithDelete { class IntrusivePtrBaseWithDelete : public IntrusivePtrBase<IntrusivePtrBaseWithDelete> {
public: public:
inline IntrusivePtrBaseWithDelete() : ref_count(0) {}
inline IntrusivePtrBaseWithDelete(const IntrusivePtrBaseWithDelete&)
: ref_count(0) {} // don't copy construct the reference count!
virtual ~IntrusivePtrBaseWithDelete() {} virtual ~IntrusivePtrBaseWithDelete() {}
protected: protected:
/// Delete this object /// Delete this object
virtual void destroy() { virtual void destroy() {
delete this; delete this;
} }
private: template <typename T> friend void intrusive_ptr_release(IntrusivePtrBase<T>*);
AtomicInt ref_count;
friend void intrusive_ptr_add_ref(IntrusivePtrBaseWithDelete*);
friend void intrusive_ptr_release(IntrusivePtrBaseWithDelete*);
}; };
inline void intrusive_ptr_add_ref(IntrusivePtrBaseWithDelete* p) {
++p->ref_count;
}
inline void intrusive_ptr_release(IntrusivePtrBaseWithDelete* p) {
if (--p->ref_count == 0) {
p->destroy();
}
}
#else #else
#define DECLARE_POINTER_TYPE DECLARE_SHARED_POINTER_TYPE #define DECLARE_POINTER_TYPE DECLARE_SHARED_POINTER_TYPE
#define intrusive_ptr shared_ptr #define intrusive_ptr shared_ptr
...@@ -235,7 +228,7 @@ inline shared_ptr<T> new_shared9(const A0& a0, const A1& a1, const A2& a2, const ...@@ -235,7 +228,7 @@ inline shared_ptr<T> new_shared9(const A0& a0, const A1& a1, const A2& a2, const
virtual ~IntrusivePtrVirtualBase() {} virtual ~IntrusivePtrVirtualBase() {}
}; };
class IntrusivePtrBaseWithDelete { class IntrusivePtrBaseWithDelete : public IntrusivePtrBase<IntrusivePtrBaseWithDelete> {
public: public:
virtual ~IntrusivePtrBaseWithDelete() {} virtual ~IntrusivePtrBaseWithDelete() {}
protected: protected:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment