Ogre & Gamecenter - Problem with presentModalViewController

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

Ogre & Gamecenter - Problem with presentModalViewController

Post by azrialelf »

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!
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by masterfalcon »

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.
azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am
x 7

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by azrialelf »

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?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by masterfalcon »

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.
azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am
x 7

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by azrialelf »

I'm using 1.7, will that still work?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by masterfalcon »

No, view controller support was added in 1.8.
Igor Gedymin
Gnoblar
Posts: 8
Joined: Sat Apr 28, 2012 1:06 pm
x 4

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by Igor Gedymin »

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];
azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am
x 7

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by azrialelf »

Wow - Thanks Igor! I'm excited to try this out!
azrialelf
Gremlin
Posts: 155
Joined: Wed Jul 11, 2007 2:43 am
x 7

Re: Ogre & Gamecenter - Problem with presentModalViewControl

Post by azrialelf »

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?