Ogre & Gamecenter - Problem with presentModalViewController

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am

Ogre & Gamecenter - Problem with presentModalViewController

Post by azrialelf » Sun Aug 12, 2012 2:22 am

Hey Guys!
I'm trying to update my game with Game Center support and I've come across an error that ventures outside my area of expertise. I'm simply trying to load the GameCenter Leaderboards and Achievements, using Masterfalcon's sample project.
Here is the code to load the GameCenter views, straight from Apple's guide http://developer.apple.com/library/ios/ ... 04-CH6-SW9

Code: Select all

KLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
    if (leaderboardController != nil)
    {
        leaderboardController.leaderboardDelegate = self;
        [self presentModalViewController: leaderboardController animated: YES];
    }
The error I get is:

Code: Select all

2012-08-11 21:17:12.642 DeadmansRun[2805:707] -[AppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance 0x1ce5ff80
2012-08-11 21:17:12.645 DeadmansRun[2805:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance 0x1ce5ff80'
I searched as much as I could but the best help I could find was "You cannot use presentModalViewController:animated: directly from an AppDelegate. It must be presented from an instance of UIViewController. This is the cause of the error." - It's helpful but unfortunately I don't know objective C well enough to be able to implement a fix.

I realize this isn't really an Ogre problem, but it's a problem I'm having trying to use Ogre so I was hoping one of you programming gurus could provide some insight!
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by masterfalcon » Sun Aug 12, 2012 7:44 am

Yeah sounds like you need to call that from an UIViewController subclass. You may be able to attach it to the view controller that Ogre creates(in 1.8 only). Use the getCustomAttribute function to get the "VIEWCONTROLLER" attribute from your window instance.
0 x

azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by azrialelf » Mon Aug 13, 2012 2:35 pm

masterfalcon wrote:Yeah sounds like you need to call that from an UIViewController subclass. You may be able to attach it to the view controller that Ogre creates(in 1.8 only). Use the getCustomAttribute function to get the "VIEWCONTROLLER" attribute from your window instance.
So - I should create a UIViewController subclass, attach it to .... my main window?
And then replace the 'self' in the Apple provided gamecenter code with the UIViewController object?
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by masterfalcon » Mon Aug 13, 2012 3:25 pm

You could either create your own or use the one that Ogre already makes and retrieve a pointer to it using getCustomAttribute. If you create your own you will need to inform Ogre of it when the window is created by passing it in the miscParams argument.
0 x

azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by azrialelf » Mon Aug 13, 2012 3:38 pm

I'm using 1.7, will that still work?
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by masterfalcon » Mon Aug 13, 2012 4:31 pm

No, view controller support was added in 1.8.
0 x

Igor Gedymin
Gnoblar
Posts: 8
Joined: Sat Apr 28, 2012 1:06 pm

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by Igor Gedymin » Mon Feb 11, 2013 2:48 pm

I found a solution for 1.7.3

1. Add class UIViewController to your project (check XIB in wizard)
2. Get params "WINDOW" and "VIEW" from render window:

Code: Select all

unsigned long hWnd = 0;
m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);
    
unsigned long hView = 0;
m_pRenderWnd->getCustomAttribute("VIEW", &hView);
these are UIWindow and UIView.

3. Then create UIViewController instance and assign:

Code: Select all

mainWindow = (UIWindow*) hWnd;
mainView = (UIView*) hView;
rootViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
rootViewController.view = mainView;
mainWindow.rootViewController = rootViewController;
Now, you can use rootViewController for Game Center
4. [rootViewController presentModalViewController: leaderboardController animated: YES];
0 x

azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by azrialelf » Fri Mar 01, 2013 2:45 am

Wow - Thanks Igor! I'm excited to try this out!
0 x

azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by azrialelf » Tue Mar 05, 2013 7:29 am

Ok I gave it a shot - Here's my implementation:

Code: Select all

- (void)go {
	
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    //Creates Ogre framework
    //This handles input and the 'main loop'
    new OgreFramework();
    if(!OgreFramework::getSingletonPtr()->initOgre("Deadman's Run v1.0",
												   &game, 0))
		return;
    
    //NEW OGRECODE as per FORUMS
    unsigned long hWnd=0;
    OgreFramework::getSingletonPtr()->m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);
    
    unsigned long hView=0;
    OgreFramework::getSingletonPtr()->m_pRenderWnd->getCustomAttribute("VIEW", &hView);
    
    window = (UIWindow*) hWnd;
    gameView = (UIView*) hView;
    //mainVC = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    mainVC=[[UIViewController alloc] init];
    mainVC.view=gameView;
    window.rootViewController= mainVC;
    
However, here is the result:
Image

If I put the code after the first frame is rendered, the result changes, but is still wrong.
If I take this code block out, it goes back to working normally.

Any ideas?
0 x

Post Reply