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

Author Topic: Error creating SFML::RenderWindow with windowHandle supplied by the OS (Mac)  (Read 4294 times)

0 Members and 1 Guest are viewing this topic.

starmessage

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • View the moon phase and write your name in the stars
Hello,

I am making a Win/Mac screensaver.
In both platforms, the OS give you the window handle on which you must draw the screensaver.

It seem that on MAC I cannot create a SFML::RenderWindow using the native window handle.
This works Ok on windows.

As this is part of a bigger project, I do not have a minimal project and I am extracting here the code that is on the way of the RenderWindow creation. I hope you see some obvious mistake.

I am using SFML 2.0 / RC 102.

In MAC OSX you create a subclass of ScreenSaverView which is a subclass of NSView
This object is created by the OS.

In the function startAnimation you have the chance to find the window handle by using
NSWindow *windowHandle = [self window];
 
   

I eventually pass this handle to my "TmioanCanvasSFML"  class.

class TmioanCanvasSFML: public TmioanCanvasAbstract
{
protected:
        NativeWindowHandle windowHandle;
        sf::RenderWindow sfmlWindow;

public: // constructor  
       
        TmioanCanvasSFML(const NativeWindowHandle wHandle):  
                        windowHandle(wHandle),
                        sfmlWindow(wHandle)  // THE ERROR OCCURS HERE, in the initialization list
                {
                TmioanUtils::DebugLogLn("TmioanCanvasSFML(wHandle) constructor start");
                TmioanUtils::DebugLogLn("wHandle:", (long) wHandle);
       
                       
                if (!wHandle)
                        TmioanUtils::DebugLogLn("Error: TmioanCanvasSFML(wHandle) with NIL wHandle");
                       
                };
 
   

The native window handle is defined as
#include <Cocoa/Cocoa.h>
// Window handle is NSWindow (void*) on Mac OS X - Cocoa
typedef NSWindow* NativeWindowHandle;
 

When sfmlWindow(wHandle) is called, I see in the console the error:
Code: [Select]
memory_pressure: 0memory_pressure: 02012-12-02 20:17:27.906 ScreenSaverEngine[2414:a0f] invalid context
Error. Unable to create the context.
TmioanCanvasSFML(wHandle) constructor start
wHandle: 8590489248

The debugger shows the error in this screenshot.
http://oi45.tinypic.com/2u88jcz.jpg



Thank you for any ideas on what to search for….


-----------
By the way, I have a suggestion for a new (simple) function for SFML.
sf:getVersion()
Returns the textual version of SFML, eg. "2.0.094"
I want to log this number in the program's logfile that is sent to me by users in case of problems.
I am logging there all parameters of the OS and all available versions of linked libraries.
« Last Edit: December 02, 2012, 09:17:04 pm by starmessage »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
By the way, I have a suggestion for a new (simple) function for SFML.
sf:getVersion()
There are two macros that define the version of SFML: SFML_VERSION_MAJOR and SFML_VERSION_MINOR.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Quote
I am using SFML 2.0 / RC 102.
102? What did I miss recently ?

First, try to update your SFML by recompiling it from source (see cmake tutorial). Some stuff have changed since the RC was release.

Quote
In MAC OSX you create a subclass of ScreenSaverView which is a subclass of NSView
[...]
In the function startAnimation you have the chance to find the window handle
You can also give self as a handle since it inherits from NSView.
SFML / OS X developer

starmessage

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • View the moon phase and write your name in the stars
1)
RC 102  :)

I got that number from the download filename of the 2.0 snapshot.
At that time it was 102, now it is 110
"LaurentGomila-SFML-2.0-rc-110-g288bc87.tar.gz"

I kept it as a number of build, so I could now how much the 2.0 snapshot has advanced since then.

I will recompile the rc-110 to see if my problem has been fixed by the work already done in the SFML.

I was hoping this number is also somewhere inside the SFML as a getVersion().
I understand that only the major and minor (2.0) numbers are available in the code.

2)
I tried to supply the NSview as well but got the same error.
« Last Edit: December 03, 2012, 10:48:58 pm by starmessage »

starmessage

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • View the moon phase and write your name in the stars
I recompiled the lastest version (RC-110) of SFML 2.0
The error when trying to create the renderWindow remains
Any ideas?

Code: [Select]
TmioanScreenSaverAbstract::initWithWindowHandle: 8590578624
memory_pressure: 0memory_pressure: 02012-12-06 20:15:00.246 ScreenSaverEngine[1451:a0f] invalid context
Error. Unable to create the context.
2012-12-06 20:15:00.250 ScreenSaverEngine[1451:a0f] invalid context
Program received signal:  “EXC_BAD_ACCESS”.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
did you try to debug it and extract more information about the crash with a debugger ?
SFML / OS X developer

starmessage

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • View the moon phase and write your name in the stars
The error happens inside

sf::RenderWindow  sfmlWindow(wHandle);

I could debug my program, but are you suggesting to debug the SFML source files? I am not sure if I am able to suceed on that.

Can I have feedback from other member if they are creating without problems a SFML renderwindows using the window handle of an existing OS window ?

           

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
I already created screensaver for windows, now i'm doing it for mac, it's realy a pain, because of gc settings and else. But on my Mac i got it working with sfml, just recompiled all my libraries and sfml as universal binaries with propper gc settings.

try not to pass window but view :
Code: [Select]
handle = [self window];
handle = self; <<<

P.S. don't you want to update you xcode ?

« Last Edit: December 08, 2012, 09:27:17 am by Acrobat »

starmessage

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • View the moon phase and write your name in the stars
thanks. Your suggestion worked:
   NSWindow *windowHandle = self;

when I called it from inside the function startAnimation.

When I tried it inside the function initWithFrame, it did not work.

But in general, it behaves in an unstable way: when I reverted the changes back, it did not work.
I am checking if the exceptions are pilling up in the ScreensaverEngine when I debug, and next runs behave diffrently because of this "history".

P.S. I created a virtual mac to to test also xcode 4.