Re: Custom memory manager and calling unref for Cairo::RefPtr<Cairo::Context>



Roman Yazmin wrote:
Hi everyone.

I'm using custom memory manager and operators like new and delete are overloaded.

Sample code:

    bool MyDraw::on_expose_event(GdkEventExpose* event)
    {
        Glib::RefPtr<Gdk::Window> window = get_window();
        if(window)
        {
           Cairo::RefPtr<Cairo::Context> cr =
    window->create_cairo_context();
        }
    }



When unref for Cairo::RefPtr<Cairo::Context> is called (cr goes out of scope)
I have a crash.

Crashing here: cairomm/refptr.h

    template <class T_CppObject> inline
    void RefPtr<T_CppObject>::unref()
    {
      if(pCppRefcount_)
      {
        --(*pCppRefcount_);

        if(*pCppRefcount_ == 0)
        {
          if(pCppObject_)
          {
            delete pCppObject_;
            pCppObject_ = 0;
          }

          delete pCppRefcount_; //<<<<<<-------------------------
    crash here, (in my overloaded delete operator, he can't found some
    internal information and assertion happens )
          pCppRefcount_ = 0;
        }
      }
    }


As I understand, pCppRefcount is allocated not with my overloaded new operator.
It seems like it is allocated somewhere by create_cairo_context() method.
I am using Windows platform, and allocating memory in DLL and free it
in host application is not good idea, especially with different allocation methods. Is any idea how to resolve this issue?
I'm still want to use my own memory manager for new/delete.

Thanks.

Sorry it took so long to reply.

the pCppRefcount_ member is not allocated in cairo, it is allocated using 'new' (see line 228: http://cgit.freedesktop.org/cairomm/tree/cairomm/refptr.h#228). Since it's defined in a header, it should be using your custom new operator. I just did a very crude test and i was able to override new and delete and both the creation and deletion of the pCppRefcount_ member used my custom allocation functions. Is it possible that your custom allocator has a bug?


Jonner


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]