I think i figured it out, how to solve this issue :
// Owner.h
#import <Foundation/Foundation.h>
@class NSOpenGLContext;
@interface Owner : NSObject
+(void)addContext: (NSOpenGLContext *)context;
+(void)delContext: (NSOpenGLContext *)context;
@end
// Owner.m
#import "Owner.h"
static NSMutableArray * contexts = nil;
@implementation Owner
+(void)addContext: (NSOpenGLContext *)context
{
if (!contexts)
contexts = [[NSMutableArray alloc] init];
[contexts addObject:[context retain]];
}
+(void)delContext: (NSOpenGLContext *)context
{
if (contexts) {
[contexts removeObject:context];
if ([contexts count] == 0)
[contexts release];
}
}
@end
In SFContex.mm after creating of Context add:
[Owner addContext:m_context];
in destructor after releasing m_context :
[Owner delContext:m_context];
Let me know what do you think about this solution
The problem with Garbage Collector + mixing ObjC with C++ is that native class can't own ObjC object
Where did you find this information ? I couldn't find any good literature about this with some quick google search..
It was just random post somewhere deep in net (i can't find it anymore, but it works).
P.S. there also something with input delegate (only when you use sfml window in NSView), i just commented it out for my screensaver. (no problems in simple applications)
Can you elaborate a little bit ?
During working on screensaver, there was random crashes inside sfml on mouse move event (in WindowImplCocoa::mouseMovedIn(void)). So i just commented line
[m_delegate setRequesterTo:this];
in constructor that takes WindowHandle. ScreenSaverView handle it automatically (just do drawings). Did not tested it in simple NSView, but there is no problem in simple SFML applications.
I'm not sure, profiller crashes
the profiler and not your app ? what happen when you use a debugger on your app ?
This is something strange, GC Monitor crashes after 10 sec running (every time), but it helped me to solve the first issue.
P.S. I configured the environment to debug screensaver, but i still can't do anything on breakpoint in IDE, i can see local values and call stack.
Yes.
[[NSGarbageCollector defaultCollector] disableCollectorForPointer:pointer]
worked (i did this for all ObjC pointers)
don't forget to use NSAutoreleasPool in main function