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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:20:46+00:00 2026-05-13T10:20:46+00:00

As you can see in the code below, I have an Abstract Base Class

  • 0

As you can see in the code below, I have an Abstract Base Class “HostWindow”, and class that derives from it “Chrome”. All the functions are implemented in Chrome. The issue is, I can’t call functions in Chrome if they’re virtual.

class HostWindow : public Noncopyable {
public:
    virtual ~HostWindow() { }

    // Pure virtual functions:
    virtual void repaint(const IntRect&, bool contentChanged, bool immediate = false, bool repaintContentOnly = false) = 0;
    virtual void scrollbarsModeDidChange() const = 0;
}

class Chrome : public HostWindow {
    // HostWindow functions:
    virtual void repaint(const IntRect&, bool contentChanged, bool immediate = false, bool repaintContentOnly = false);
    virtual void scrollbarsModeDidChange() const;

    void focus() const;
}

So lets say we have an instance of Chrome, and we call a few functions:

WebCore::Chrome *chrome = new Chrome();
chrome->repaint(IntRect(), true); // Null pointer error
chrome->focus(); // returns void (works)

The null pointer error I get whenever I call virtual functions is:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000008

Any idea what’s happening?

Update:
As many of you pointed out – this code actually runs. Unfortunately I can’t provide a more full example, since the code is deep inside WebCore (WebKit). However, I have narrowed the problem down. If I create a Chrome instance manually, calling virtual functions work. So the issue is with this particular chrome instance – it can’t instantiated properly. Now, the Chrome instance is instantiated in a constructor of another class. I’ll investigate further…

Update 2:
Ok, examining the vtable on the offending instance shows that it’s null; from GDB:

p *(void **)chrome
$52 = (void *) 0x0

A normal instance has a correct vtable. So, I’ve got to work out why the vtable is nil – I wonder how that could happen? Maybe because it’s being instantiated in some other classes Constructor?

Update 3:
Looks like I’m correct about the issue being it’s instantiation inside another class’ constructor.

So, before the instantiation looked like this:

Page::Page(ChromeClient* chromeClient, ...)
    : m_chrome(new Chrome(this, chromeClient))

And m_chrome is an invalid instance, with a nil vtable.
I’ve changed the instantiation so it happens when the first time the variable is needed (this involves saving ChromeClient for later):

Page::Page(ChromeClient* chromeClient, ...)
    : m_chrome(0)
    , m_chrome_client(chromeClient)

Chrome* Page::chrome() const {
  if(!m_chrome) {
    m_chrome = new Chrome(this, m_chrome_client);
  }
  return m_chrome;
}

Now the Page::chrome() instance is the correct one, with the proper vtable – rather odd!

Update 4:
Last update, I promise :). Ok, so I’ve pinpointed it down exactly. You get the correct instance, with the vtable, if you instantiate it in Page constructor’s body. If you instantiate it in Page constructor’s head, it doesn’t have a vtable. Is there any limitation in the types of variable setting you can do in a constructor’s head? I guess that’s another Stackoverflow question.

Thanks guys for being so helpful.

  • 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-05-13T10:20:47+00:00Added an answer on May 13, 2026 at 10:20 am

    Yes, the ‘this’ pointer is zero. Add 8 to get an offset, and there’s your fault. You apparently don’t have any actual object at all.

    Since you haven’t posted enough code to really come to grips, I’m guessing. Either the entire this pointer is 0, or the virtual function table pointer is 0, perhaps because the object has been deleted after it was created and before you try to call it.

    The best advice I can give you is to create a much smaller test-tube. Either you will find your problem or you will end up with a postable example.

    The vtbl isn’t in place in an instance until the end of the construction process. In fact, the spec requires progressive modification of the vtbl to match the state of construction of the class hierarchy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table defined (see code snippet below). How can I add a
Quite often in ANSI C code I can see parenthesis sorrounding a single return
Here's some code I saw once. Can you see what's wrong with it? [updated]
I can see people asking all the time whether multiple inheritance should be included
I can see some options available: 1) Use PEAR's POP3 class --> tried it,
I can see in the postgresql logs that certain simple queries (no joins and
As you can see this is a question from a non web developer. I
As you can see below, in the constructor I'm instantiating a validation object so
We can see in a directory files ordered by Name in Windows Explorer. If
I can see line numbers in my error logs in our development environment, in

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.