Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8000669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:52:35+00:00 2026-06-04T15:52:35+00:00

I am attempting to write a C++ wrapper of OpenVG, which is very Open-GL

  • 0

I am attempting to write a C++ wrapper of OpenVG, which is very Open-GL like in its design.
here is a simple wrapper for a path handle:

class Path {
        VGPath handle;

    public:
        Path() :
        handle(vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
            1,0,0,0, VG_PATH_CAPABILITY_ALL)) 
        { 
        std::cout << "Path Handle created : " << (void*)handle << '\n';
        }

        ~Path() {
            std::cout << "Path destroyed  : " << (void*)handle << '\n';
            vgDestroyPath(handle);
        }

    };

unfortunately, openVG requires a context to function and will abort if vgCreatePath is called with no openVG context.
This prevents me from creating (for testing purpose) a global Path object object in my code, since it is build before I can create a openVG context (I do so in the main).
Is there any workaround to prevent this?

I think that leaving the handle unitialized at the object construction is a very bad idea… should I force the creation of a global context when I’m creating a Path object if no context is present?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:52:36+00:00Added an answer on June 4, 2026 at 3:52 pm

    Is there any workaround to prevent this?

    Yes, use smart pointers, create it on demand using some kind of “factory” function, store it as long as it is needed in any variable.

    In C++03:

    typedef boost::weak_ptr<Path> PathWeakPtr;
    typedef boost::shared_ptr<Path> PathPtr;
    
    PathPtr createPath(){
        static PathWeakPtr lastPath;
        PathPtr result = lastPath.lock();
        if (!result){
            result.reset(new Path());
            lastPath = result;
        }
        return result;
    }
    

    …

    void doSomething(){
        PathPtr path = createPath();//points to same path as in main*()
        ...
    }
    
    int main(int argc, char** argv){
        PathPtr path = createPath();//initialization
        doSomething();
        return 0;
    }
    

    In C++11 use:

    typedef std::weak_ptr<Path> PathWeakPtr;
    typedef std::shared_ptr<Path> PathPtr;
    

    instead of

    typedef boost::weak_ptr<Path> PathWeakPtr;
    typedef boost::shared_ptr<Path> PathPtr;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to write an Android app which will allow me to read
I'm attempting to write a very basic script using javascript. What I want to
I'm attempting to write a wrapper so that my C# application can use a
I'm attempting to write a Python wrapper for poker-eval, a C static library. All
I am attempting to write a interpreter that will turn a string like: vector(random(0,
I am attempting to write a function which will operate on a std::map of
I'm attempting to write a text editor. I'm unable to open a file. Why?
I am attempting to write a simple script to recursively rip through a directory
I'm attempting to write a SQL search which will allow return any records which
I'm attempting to write a simple buffer overflow using C on Mac OS X

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.