[SOLVED] IOS - Multiple inheritance problem: bad alloc!

[SOLVED] IOS - Multiple inheritance problem: bad alloc!

I’m testing out my cocos2d-x c++ game on ios and i’ve noticed a bug(?).
I don’t really know if this is a bug and I also think that this is not related to the framework.

I integrated firebase::admob to my game and on Android it works fine!
On IOS it works fine but when the framework tries to call my listener everythink crashes.

Here is my Listener Class:

class MyRewardedVideoListener {

    virtual void rewardPlayer(firebase::admob::rewarded_video::RewardItem reward) = 0;
    virtual void handleError() = 0;
    virtual void refuseReward() = 0;

Here is the implementation:

class ChargeBatteryPopUp :	public PopUp, public MyRewardedVideoListener {


	void rewardPlayer(firebase::admob::rewarded_video::RewardItem reward) override;
	void handleError() override;
	void refuseReward() override;



I have a pointer to this class in the admob lister that calls this methods when those things happen.
The pointer is of this type:

MyRewardedVideoListener * myListener;

But when i try to call a method, for example:


The game crashes and i get a BAD_ACCESS exception:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

These classes work fine on android so I don’t know why i’m getting this problem on IOS.
Could be because of the fact that Objective-C does not support multiple inheritance?
I have not fount anything useful on the web that’s why I’m writing this post. I don’t even know if this is the right place to ask this.

If you need more information let me know!


Have you attempted to check if it works correctly after you create an object of the ChargeBatteryPopup class?

Do these tests on iOS:

auto popup = ChargeBatteryPopup();
popup->rewardPlayer(dummyData); // This should work

auto listener = dynamic_cast<MyRewardedVideoListener*>(popup);
listener->rewardPlayer(dummyData); // This should also work

If you verify that they are in fact working, then your issue is perhaps related to myListner being null for whatever reason, and not related to the fact that you’re using multiple inheritance.

Just add exception breakpoint in xcode, and your program will automatically stop just on exception, so you can inspect and easily understand where error/nullpointer is.

I have already checked multiple time but the pointer seems to be ok, in fact it works fine on Android so i do not understand why shouldn’t it work on ios. I will try

Thanks for your help!

I have tried to create a brand new project and recreate the situation but i don’t get the error, so the problem must be somewhere else! I’ll let you know.

Allright guys, the problem was that I’ve created all those method thinking that my code was “paused” when the ad screen was covering the app ui.
This assertion was right on Android, but not on IOS.
So i’ve changed a little bit my classes and method to work without that asserition.
(I was deleting the object too early)

Thanks for your help guys.
Marking this as resolved.
Best regards,

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.