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 8244751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:57:32+00:00 2026-06-07T21:57:32+00:00

I have been beating my head around this issue of static versus non-static, callback

  • 0

I have been beating my head around this issue of static versus non-static, callback functions, function pointers, etc… My goal is to access data of a struct outside the scope of my callback interface. I am trying to do this within my class called TextDetect. I thought I was on track when I asked this question: Avoiding a static member function in c++ when using a callback interface from C
However, I still can’t access the data without losing scope over the data that I am most interested. At runtime, I get “Access violation reading location …” I’ll point it out below where it fails.
I implemented the answer to my previous question as the following class, shown entirely (Note: vtrInitialize is part of a 3rd party api code int vtrInitialize(const char *inifile, vtrCallback cb, void *calldata);):

 class TextDetect {
     const char * inifile;
     vtrImage *vtrimage;
     int framecount;
 public:
     TextDetect();
     ~TextDetect();
     void vtrCB(vtrTextTrack *track);
     static void vtrCB_thunk(vtrTextTrack *track, void *calldata);
     int vtrTest(cv::Mat);
     bool DrawBox(cv::Mat&);
     vtrTextTrack *texttrack;
 };

 TextDetect::TextDetect() : inifile("vtr.ini")
 {
      if (vtrInitialize(inifile, vtrCB_thunk, static_cast<void *>(this) ) == -1) 
         std::cout << "Error: Failure to initialize" << std::endl;
         vtrimage = new vtrImage;
  }


  int TextDetect::vtrTest(cv::Mat imagetest)
  {
    /*store image data in an image structure*/
  }

   void TextDetect::vtrCB(vtrTextTrack *track)
   {
     /*send data to command line from callback */                   

I’ve tried copying the data I need a variety of ways and nothing works (this code is a continuation from above):

     //texttrack = track;
     //texttrack = new vtrTextTrack (*track);
     memcpy(texttrack,track,sizeof(*track));
     //vtrTextTrackFree(track); 

    }
  void TextDetect::vtrCB_thunk(vtrTextTrack *track, void *calldata)
  {
       static_cast<TextDetect *>(calldata)->vtrCB(track);
  }

This is the member function were I want the data to be used. Texttrack is public member so I might need it outside my class as well (this code is a continuation from above):

  bool TextDetect::DrawBox(cv::Mat& tobeboxed)
  {

And I get the access violation error at runtime here at this line of code (this code is a continuation from above):

  if (texttrack->best->ocrconf > 90)
     {
        /*do some more stuff*/
   }
  }
  • 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-07T21:57:34+00:00Added an answer on June 7, 2026 at 9:57 pm

    Hopefully I’m understanding this correctly.

    It seems to me that the problem is trying to copy those vtrTextTrack structs improperly.
    This:

    //texttrack = track;
    

    just copies the pointer. If the owner of the struct (probably the caller of the callback function) destroys/deletes the vtrTextTrack, then you’re holding on to an invalid pointer.

    This one:

    memcpy(texttrack,track,sizeof(*track));
    

    will copy all the members of the vtrTextTrack, but will not copy what’s being pointed to by it’s member pointers (e.g. texttrack->best). Again, if the owner destroys/deletes the track, then you’re holding on to invalid pointers.

    And since

    //texttrack = new vtrTextTrack (*track);
    

    didn’t work, I’m guessing that vtrTextTrack doesn’t provide a copy constructor.

    As for a workaround, first check if your third party library provides a function to copy these structs. If that’s not the case (could this be by design?), then you may have to implement one yourself. This might be hard because there might be all kinds of internals that you don’t know about. If you don’t need the whole vtrTextTrack, I’d say define another struct and store only the information you need. Something along the lines of

    SomeType* bestCopier(SomeType* src)
    {
         SomeType* temp;
         /* copy over struct */
         return temp;
    }
    
    Foo* fooCopier(Foo* src)
    {
        /*...*/
    }
    
    struct myTextTrack 
    {
    public:
        myTextTrack(vtrTextTrack* src)
        {
            //copy over stuff
            m_best = bestCopier(src->best);
            m_foo = fooCopier(src->foo);
        }
    
    private:
        /* the members you care about*/
        SomeType* m_best;
        Foo * m_foo;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I've been beating my head against the wall of this issue for several
Well, I have been beating my head over this one for some time now,
I've been beating my head against this for awhile to no avail. I have
I'm nearly finished with this project but I have been beating my head against
I have been beating my head in the wall all evening on this, can
I'm completely new to jQuery/javascript and have been beating my head against this simple
Here's what i have been beating my head against for a day now. I
I've been beating around on this thing all day and it's driving me nuts!
I have an odd problem that I've been beating my head into a wall
Been beating my head against a wall trying to get this to work -

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.