Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: window becomes unresponsive on launch  (Read 4193 times)

0 Members and 1 Guest are viewing this topic.

codecranker

  • Guest
window becomes unresponsive on launch
« on: September 30, 2012, 01:44:07 am »
I just started using SFML. I downloaded the SFML v1.6 and using it on my mac with mountain lion and xcode 4.4.1.
I manage to complete the starter tutorial that displays a yellow circle on the screen with a black background.
Everything runs fine except one thing. As soon as I launch the application, the mouse pointer changes to a rainbow wheel and I can no longer close my application using the application close button neither I can quit the application using the main apple menu. It seems like the window has become unresponsive.
I have to go back to my xcode project and stop the application. Anyone has any idea as to why it is happening?
should I try upgrading to SFML v2.0 and see if the problem still persists?

I am using the same code example that comes with the default xcode templates. The reason why I have added the C style linkage is because I am not using interface builder xib file and instead creating NSApplication object in the code itself. The startup code for NSApplication only accepts objective-c and C. I am sure the problem is somewhere else.

Lemme know if I can provide any more relevant information.

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////

#ifdef __cplusplus
extern "C" {
#endif

int sfml_main(int argc, char *argv[])
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(1024, 768), "SFML Graphics");
   
    App.ShowMouseCursor(true);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear screen
        App.Clear();

        // Draw apredefined shape
        App.Draw(sf::Shape::Circle(200, 200, 100, sf::Color::Yellow, 10, sf::Color::Blue));

        // Finally, display the rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}

#ifdef __cplusplus
}
#endif

 
« Last Edit: September 30, 2012, 03:14:36 am by codecranker »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: window becomes unresponsive on launch
« Reply #1 on: September 30, 2012, 03:01:38 am »
First off please use Code=Cpp tag. It really helps with the readability of code.

Second, it looks like the problem comes from your mac (guessing here since i don't own a mac) thinking your application is in an infinite loop (and therefore is stuck there) so you then can't do anything with the window. Try setting a framerate limit or using vsync. Just remember to use one or the other, not both at the same time.
« Last Edit: September 30, 2012, 03:04:03 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

codecranker

  • Guest
Re: window becomes unresponsive on launch
« Reply #2 on: September 30, 2012, 06:49:09 am »
sorry. I didnt pay much attention to the code formatting options.

So, I tried your two suggestions with no success. Then I upgraded to SFML 2.0rc and it is working fine now, no more rainbow wheel of death. Not a single line of code change, dunno what was wrong.

I guess SFML 1.6 is not compatible with OSX Mountain Lion or vice versa.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: window becomes unresponsive on launch
« Reply #3 on: September 30, 2012, 07:30:00 pm »
#ifdef __cplusplus
extern "C" {
#endif
Wait what? Don't do that... :o
Or is that some strange Mac/Object-C related thing?

Well SFML 1.6 is anyways over 3 years old, has many known bugs and lacks quite a bit a feature so IMHO there's no reason to use SFML 1.6 anymore. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: window becomes unresponsive on launch
« Reply #4 on: September 30, 2012, 08:10:27 pm »
Quote
Wait what? Don't do that...
Or is that some strange Mac/Object-C related thing?
It's a standard thing, but it doesn't make sense to apply it to a function definition, it's usually for declarations. Declaring a function as extern "C" makes the linker treat it as a C function.
Laurent Gomila - SFML developer

codecranker

  • Guest
Re: window becomes unresponsive on launch
« Reply #5 on: September 30, 2012, 11:57:46 pm »
I did declare it as extern in my NSApplication derived class. Xcode throws mach-o linker error if I remove this extern "C" thingy from the function definition. I guess its dependent on compiler implementation, may be MS VC++ compiler behaves differently. I also dont want to mix C and C++, I just couldn't found any other way.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: window becomes unresponsive on launch
« Reply #6 on: October 01, 2012, 09:57:17 am »
Quote
I did declare it as extern in my NSApplication derived class.
What are you trying to do with your NSApp object ?
SFML / OS X developer

codecranker

  • Guest
Re: window becomes unresponsive on launch
« Reply #7 on: October 02, 2012, 05:04:49 am »
Nothing special. I kept it really simple.
I created the NSApp --> set the delegate to my derived NSApplication class. Wait for the applicationDidFinishLaunching notification and then called the sfml_main. I am not using any interface builder file because I dont like IB at all :) instead I am directly invoking a .m class from the application's main.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: window becomes unresponsive on launch
« Reply #8 on: October 02, 2012, 08:55:42 am »
Two things :

First, I'm happy to see that a code structure such as yours, that was never tested nor simply thought about, actually works!  ;D

Second, why don't you simply use a classic C++ project structure, that is a main.cpp file and no .m files at all ? I'm curious of the benefit of your approach. Especially on the mix C++/Objective-C ('cause you're using .m files the compiler will think it's Obj-C). You don't have any compatibility issues at all ?
SFML / OS X developer

codecranker

  • Guest
Re: window becomes unresponsive on launch
« Reply #9 on: October 03, 2012, 01:37:37 am »
Haha. Thanks.
It works without using any C-linkages too by changing the file extension from .m to .mm.

For second: its because you have to write some objective-c code to create a cocoa application or if you wanna do some other cocoa window management. objective-c code can only reside in either .m or .mm. The difference between the two being that .m can take objective-C and C code and .mm can take objective-C and C++ code. If you are using .m then you have to use c-linkages to invoke the C++ code.
Your application's main can be one or the other. Once the cocoa application instance is created you can pass the control to your game's main loop or whatever. In my case, I am passing control to sfml_main(). There you can create a sfml graphics/opengl window that sits on top of the cocoa application.
dont imagine cocoa application as another window, its just a fictitious application container.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: window becomes unresponsive on launch
« Reply #10 on: October 03, 2012, 09:58:05 pm »
I know the difference between .m and .mm; Obj-C and Obj-C++. That was not my point. But I have to admit I was not very clear in my previous message.

My point was more about the advantage of launching a C++ "main" from an Obj-C one. If you don't need any Cocoa or any Obj-C framework I advise using directly C++. This doesn't mean you can't build an application bundle. Have a look at the Xcode template for SFML.

There are mainly two reasons for using C++ directly :

a/ It's straightforward. No need of additional files. No need of "redirecting" the main function.

b/ Obj-C++ is not a super set of C++ and Obj-C++. There are incompatibilities. It really depends how you mix the stuff together but at some point you might end up with incomprehensible and subtle issues.

There is also another point, but it's not a reason as this would be more a side effect : Using such complication structure and entry point might mess up with SFML's internal. It probably won't but it might.
SFML / OS X developer

codecranker

  • Guest
Re: window becomes unresponsive on launch
« Reply #11 on: October 04, 2012, 04:09:16 am »
Yes, I totally agree. Mixing C, C++ and objective-C is never good. I was curious to try all the options just to see what works and what doesn't. Apparently, all options work :D.
I have already removed all the objective-c code and only using c++.