Wrong virtual function called

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Wrong virtual function called

1,576 Views
tschroeder
Contributor I
It doesn't look like the old CodeWarrior for MacOS is much talked about here any more, but I have a really weird problem on an Intel Mac using the old IDE 5.1.1 CodeWarrior for Mac.

I have a global variable that points to a class PerotinApp that is a subclass of the class wxApp (part of the wxWidgets open source package). This class is the "holder" for basically everything associated with the application itself. In the wxApp class there is virtual function called MacHandleAEODoc(). I have overridden this function in the PerotinApp class.

One of the first things the initialization code does is "new" one of these classes to keep in the global variable. Immediately after that the Apple Event handlers are initialized.

Normally all of this works fine, when the app is open it gets an open document apple event, the handler gets called, it in turn calls the MacHandleAEODoc() function and the document is opened correctly. On any system except the Intel Mac when the app is closed everything also works. In fact, if the very first time the app is run you start it by sending an Open Document Apple Event everything works correctly.

However, on an Intel Mac after the first time the app is run a very odd thing happens. Instead of the handler calling the PerotinApp's MacHandleAEODoc() function the wxApp's MacHandleAEODoc() function is called. In fact, if I try to force the call to the PerotinApp's function with a dynamic_class(theWxApp)->MacHandleAEODoc() the app actually crashes on an access violation at address 0.

My guess is that the virtual function table isn't set up for the subclass and the wrong function is called because it think's there's no override or "code" at 0x0 is called because the virtual function table isn't properly initialized. I was hoping maybe someone had seen something similar and had some ideas on what I might do to overcome this problem.

Thanks,

Ted Schroeder
FreeHand Systems, Inc.
Labels (1)
0 Kudos
3 Replies

416 Views
RicardoRaupp
Contributor II

Hi Ted

I posted a question similar with your in CodeWarrior for 8 bits ( CW6.2 C++ Pro) .

I´m using a 8 bits cpu...

I have 2 pure virtual function with same name but differents signatures in the base class wich I want they be implemented in the derived class.

Another funcion is called instead the one I asked.

Curious is that I checked the vtable values / location  (*picky..but...) and it seems to be ok...

It happens only if calling the function ( pure visrtual) via a base class pointer.

Have you had some feedback of your post? or solved your problem?some tipo for my problem..?

 

Thanks!!!

 

Ricardo Raupp

0 Kudos

416 Views
tschroeder
Contributor I

That was a LONG time ago, but as I remember I changed around the initialization order (I think maybe I loaded things up at run time or something) and this fixed the problem.

 

Ted

0 Kudos

416 Views
RicardoRaupp
Contributor II

OK...

 

Thanks Ted..

 

Ricardo Raupp

0 Kudos