SDL, Java and OS X 10.2

I am trying to use the java wrapper from http://jsdl.sourceforge.net

I believe that SDL is running into problems opening a Cocoa window,
etc. Is it possible to write a command line C or Java program that can
open a SDL in Cocoa or does it have to be wrapped in a .app?

The error I get:

SDL Version used: 1.2.5
-JNI- JNI_OnLoad
kCGErrorInvalidConnection : CGSNewWindow: Invalid connection
2002-11-04 20:01:07.414 java[4411] _NXCreateWindow: error creating
window (1002)
kCGErrorInvalidConnection : CGSSetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSInvalidateWindowShadow: Invalid
connection
kCGErrorInvalidConnection : CGSSetWindowListAlpha: Invalid connection
kCGErrorIllegalArgument : CGSLockWindowRectBits: Invalid window
kCGErrorFailure : Failed to create window context device.
kCGErrorFailure : CGWindowContextCreate: failed to create context.
2002-11-04 20:01:07.433 java[4411] _initWithWindowNumber: error
creating graphics ctxt object for ctxt:0, window:-1
kCGErrorFailure : CGContextResetClip: invalid context
kCGErrorFailure : CGContextReplaceTopGState: invalid context
kCGErrorInvalidConnection : CGSGetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSSetHideOnDeact: error getting current
hide-on-deactivate state
kCGErrorInvalidConnection : CGSSetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSSetEventMask: error setting client event
mask window property
kCGErrorInvalidConnection : CGSSetWindowEventMask: Invalid connection
kCGErrorInvalidConnection : CGSSetEventMask: error setting window event
mask
kCGErrorInvalidConnection : CGSSetWindowToReleaseBackingOnOrderOut:
Invalid connection
2002-11-04 20:01:07.493 java[4411] *** _NSAutoreleaseNoPool(): Object
0x3a0eea0 of class NSCFArray autoreleased with no pool in place - just
leaking
and so on…

It doesn’t have to be wrapped in a .app. However, the main entry point
needs to be the main() defined in SDLMain.m/SDLMain.h (or it needs to
accomplish the same tasks). Also, some SDL functions will need to be
called from the main thread to work - but that shouldn’t be a problem
since IIRC Java’s entry point is called from the underlying JVM’s main
thread.

After a look at the source, I think these changes need to go in Main.c,
in Java_sdl_core_Main_SDLInit just before SDL_Init is called.

The code you will need is in the CustomApplicationMain function in
SDLMain.m. Compile Main.c with the Objective-C compiler using “gcc -x
objective-c Main.c …”. Link the JNI shared library to the Objective-C
runtime with -lobjc.

I think these are the required steps. Let me know if this works nor not.

-DOn Monday, November 4, 2002, at 11:08 PM, Brian Sugar wrote:

I am trying to use the java wrapper from http://jsdl.sourceforge.net

I believe that SDL is running into problems opening a Cocoa window,
etc. Is it possible to write a command line C or Java program that
can open a SDL in Cocoa or does it have to be wrapped in a .app?

The error I get:

SDL Version used: 1.2.5
-JNI- JNI_OnLoad
kCGErrorInvalidConnection : CGSNewWindow: Invalid connection
2002-11-04 20:01:07.414 java[4411] _NXCreateWindow: error creating
window (1002)
kCGErrorInvalidConnection : CGSSetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSInvalidateWindowShadow: Invalid
connection
kCGErrorInvalidConnection : CGSSetWindowListAlpha: Invalid connection
kCGErrorIllegalArgument : CGSLockWindowRectBits: Invalid window
kCGErrorFailure : Failed to create window context device.
kCGErrorFailure : CGWindowContextCreate: failed to create context.
2002-11-04 20:01:07.433 java[4411] _initWithWindowNumber: error
creating graphics ctxt object for ctxt:0, window:-1
kCGErrorFailure : CGContextResetClip: invalid context
kCGErrorFailure : CGContextReplaceTopGState: invalid context
kCGErrorInvalidConnection : CGSGetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSSetHideOnDeact: error getting current
hide-on-deactivate state
kCGErrorInvalidConnection : CGSSetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSSetEventMask: error setting client
event mask window property
kCGErrorInvalidConnection : CGSSetWindowEventMask: Invalid connection
kCGErrorInvalidConnection : CGSSetEventMask: error setting window
event mask
kCGErrorInvalidConnection : CGSSetWindowToReleaseBackingOnOrderOut:
Invalid connection
2002-11-04 20:01:07.493 java[4411] *** _NSAutoreleaseNoPool(): Object
0x3a0eea0 of class NSCFArray autoreleased with no pool in place - just
leaking
and so on…


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

thank you for the suggestion. here is what i am trying with little
success.

added
#import <Cocoa/Cocoa.h>
SDL_CustomApplicationMain()

JNIEXPORT jint JNICALL Java_sdl_core_Main_SDLInit (JNIEnv * env,
jclass cls, jint ind)
{
SDL_CustomApplicationMain(ind);
int val = SDL_Init(ind);
return val;
}

my make command:
gcc -DUSING_GCC -framework Cocoa -framework Foundation -framework
JavaVM -framework SDL -framework SDL_image
-I/Users/bsugar/Library/Frameworks/SDL.framework/Versions/A/Headers
-I/Users/bsugar/Library/Frameworks/SDL_image.framework/Versions/A/
Headers -I/System/Library/Frameworks/JavaVM.framework/Headers/
-I/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
-c sdl/jni/*.c
gcc -DUSING_GCC -framework Cocoa -framework Foundation -framework
JavaVM -framework SDL -framework SDL_image
-I/Users/bsugar/Library/Frameworks/SDL.framework/Versions/A/Headers
-I/Users/bsugar/Library/Frameworks/SDL_image.framework/Versions/A/
Headers -I/System/Library/Frameworks/JavaVM.framework/Headers/
-I/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
-bundle -o libSDL4Java.jnilib *.o
ld: warning multiple definitions of symbol _GetPixel
SFont.o definition of _GetPixel in section (__TEXT,__text)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/QD.framework/Versions/A/QD(QD.o) definition of _GetPixel
ld: warning multiple definitions of symbol _TextWidth
SFont.o definition of _TextWidth in section (__TEXT,__text)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/QD.framework/Versions/A/QD(QD.o) definition of _TextWidth
ld: Undefined symbols:
_SDL_CustomApplicationMain
make: *** [jni] Error 1

i am a complete novice to gcc, etc (as you can tell from above) and
appreciate your help.On Tuesday, November 5, 2002, at 08:18 AM, Darrell Walisser wrote:

It doesn’t have to be wrapped in a .app. However, the main entry point
needs to be the main() defined in SDLMain.m/SDLMain.h (or it needs to
accomplish the same tasks). Also, some SDL functions will need to be
called from the main thread to work - but that shouldn’t be a problem
since IIRC Java’s entry point is called from the underlying JVM’s main
thread.

After a look at the source, I think these changes need to go in
Main.c, in Java_sdl_core_Main_SDLInit just before SDL_Init is called.

The code you will need is in the CustomApplicationMain function in
SDLMain.m. Compile Main.c with the Objective-C compiler using “gcc -x
objective-c Main.c …”. Link the JNI shared library to the
Objective-C runtime with -lobjc.

I think these are the required steps. Let me know if this works nor
not.

-D

On Monday, November 4, 2002, at 11:08 PM, Brian Sugar wrote:

I am trying to use the java wrapper from http://jsdl.sourceforge.net

I believe that SDL is running into problems opening a Cocoa window,
etc. Is it possible to write a command line C or Java program that
can open a SDL in Cocoa or does it have to be wrapped in a .app?

The error I get:

SDL Version used: 1.2.5
-JNI- JNI_OnLoad
kCGErrorInvalidConnection : CGSNewWindow: Invalid connection
2002-11-04 20:01:07.414 java[4411] _NXCreateWindow: error creating
window (1002)
kCGErrorInvalidConnection : CGSSetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSInvalidateWindowShadow: Invalid
connection
kCGErrorInvalidConnection : CGSSetWindowListAlpha: Invalid connection
kCGErrorIllegalArgument : CGSLockWindowRectBits: Invalid window
kCGErrorFailure : Failed to create window context device.
kCGErrorFailure : CGWindowContextCreate: failed to create context.
2002-11-04 20:01:07.433 java[4411] _initWithWindowNumber: error
creating graphics ctxt object for ctxt:0, window:-1
kCGErrorFailure : CGContextResetClip: invalid context
kCGErrorFailure : CGContextReplaceTopGState: invalid context
kCGErrorInvalidConnection : CGSGetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSSetHideOnDeact: error getting current
hide-on-deactivate state
kCGErrorInvalidConnection : CGSSetWindowProperty: Invalid connection
kCGErrorInvalidConnection : CGSSetEventMask: error setting client
event mask window property
kCGErrorInvalidConnection : CGSSetWindowEventMask: Invalid connection
kCGErrorInvalidConnection : CGSSetEventMask: error setting window
event mask
kCGErrorInvalidConnection : CGSSetWindowToReleaseBackingOnOrderOut:
Invalid connection
2002-11-04 20:01:07.493 java[4411] *** _NSAutoreleaseNoPool(): Object
0x3a0eea0 of class NSCFArray autoreleased with no pool in place -
just leaking
and so on…


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

thank you for the suggestion. here is what i am trying with little
success.

added
#import
SDL_CustomApplicationMain()

JNIEXPORT jint JNICALL Java_sdl_core_Main_SDLInit (JNIEnv * env,
jclass cls, jint ind)
{
SDL_CustomApplicationMain(ind);
int val = SDL_Init(ind);
return val;
}

You can’t call that code directly, it needs to be modified. The code in
CustomApplicationMain() will not work as written in SDLMain.m.

Here is the code i am referring to:On Tuesday, November 5, 2002, at 01:05 PM, Brian Sugar wrote:

void CustomApplicationMain (argc, argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;

 /* Ensure the application object is initialised */
 [SDLApplication sharedApplication];

#ifdef SDL_USE_CPS
{
CPSProcessSerNum PSN;
/* Tell the dock about us /
if (!CPSGetCurrentProcess(&PSN))
if
(!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
[SDLApplication sharedApplication];
}
#endif /
SDL_USE_CPS */

 /* Set up the menubar */
 [NSApp setMainMenu:[[NSMenu alloc] init]];
 setupAppleMenu();
 setupWindowMenu();

 /* Create SDLMain and make it the app delegate */
 sdlMain = [[SDLMain alloc] init];
 [NSApp setDelegate:sdlMain];

 /* Start the main event loop */
 [NSApp run];

 [sdlMain release];
 [pool release];

}

You could include all of that code in Main.c. But you would have to
copy other code from SDLMain.m as well (setupAppleMenu(),
setupWindowMenu(), etc). Also, you cannot call [ NSApp run] or the
releases following that. [ NSApp run ] does not return until the
application exits.

If you don’t want all that code, I think the minimum you need is this.

#import <Cocoa/Cocoa.h>

JNIEXPORT jint JNICALL Java_sdl_core_Main_SDLInit (JNIEnv * env, jclass
cls, jint ind)
{

  NSAutoreleasePool  *pool = [[NSAutoreleasePool alloc] init];

 [ NSApplication sharedApplication ];

 int val  = SDL_Init(ind);
 return val;

}

my make command:

gcc -DUSING_GCC -framework Cocoa -framework Foundation -framework
JavaVM -framework SDL -framework SDL_image
-I/Users/bsugar/Library/Frameworks/SDL.framework/Versions/A/Headers
-I/Users/bsugar/Library/Frameworks/SDL_image.framework/Versions/A/
Headers -I/System/Library/Frameworks/JavaVM.framework/Headers/
-I/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
-c sdl/jni/*.c
gcc -DUSING_GCC -framework Cocoa -framework Foundation -framework
JavaVM -framework SDL -framework SDL_image
-I/Users/bsugar/Library/Frameworks/SDL.framework/Versions/A/Headers
-I/Users/bsugar/Library/Frameworks/SDL_image.framework/Versions/A/
Headers -I/System/Library/Frameworks/JavaVM.framework/Headers/
-I/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
-bundle -o libSDL4Java.jnilib *.o
ld: warning multiple definitions of symbol _GetPixel
SFont.o definition of _GetPixel in section (__TEXT,__text)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/QD.framework/Versions/A/QD(QD.o) definition of _GetPixel
ld: warning multiple definitions of symbol _TextWidth
SFont.o definition of _TextWidth in section (__TEXT,__text)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/QD.framework/Versions/A/QD(QD.o) definition of _TextWidth
ld: Undefined symbols:
_SDL_CustomApplicationMain
make: *** [jni] Error 1

Note you’ll have to pass “-x objective-c” and “-lobjc” when in the step
you have shown above.

thanks again. appreciate you taking the time. here is where i am at:

i tried the following:

#import <Cocoa/Cocoa.h>
JNIEXPORT jint JNICALL Java_sdl_core_Main_SDLInit (JNIEnv * env, jclass
cls, jint ind)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[ NSApplication sharedApplication ];
int val = SDL_Init(ind);
return val;
}

and it compiled:

[falcon:Projects/JSDL/jsdl] bsugar% make all
gcc -DUSING_GCC -framework Cocoa -framework Foundation -framework
JavaVM -framework SDL -framework SDL_image
-I/Users/bsugar/Library/Frameworks/SDL.framework/Versions/A/Headers
-I/Users/bsugar/Library/Frameworks/SDL_image.framework/Versions/A/
Headers -I/System/Library/Frameworks/JavaVM.framework/Headers/
-I/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
-c -x objective-c sdl/jni/*.c
gcc -DUSING_GCC -framework Cocoa -framework Foundation -framework
JavaVM -framework SDL -framework SDL_image
-I/Users/bsugar/Library/Frameworks/SDL.framework/Versions/A/Headers
-I/Users/bsugar/Library/Frameworks/SDL_image.framework/Versions/A/
Headers -I/System/Library/Frameworks/JavaVM.framework/Headers/
-I/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
-bundle -lobjc -o libSDL4Java.jnilib *.o
ld: warning multiple definitions of symbol _GetPixel
SFont.o definition of _GetPixel in section (__TEXT,__text)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/QD.framework/Versions/A/QD(QD.o) definition of _GetPixel
ld: warning multiple definitions of symbol _TextWidth
SFont.o definition of _TextWidth in section (__TEXT,__text)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/QD.framework/Versions/A/QD(QD.o) definition of _TextWidth
rm -f *.o

i moved libSDL4Java.jnilib to the appropriate place and get a
segmentation fault:

SDL Version used: 1.2.5
-JNI- JNI_OnLoad
Segmentation fault

any further hand holding would be great. thanks again.On Tuesday, November 5, 2002, at 11:28 AM, Darrell Walisser wrote:

On Tuesday, November 5, 2002, at 01:05 PM, Brian Sugar wrote:

thank you for the suggestion. here is what i am trying with little
success.

added
#import
SDL_CustomApplicationMain()

JNIEXPORT jint JNICALL Java_sdl_core_Main_SDLInit (JNIEnv * env,
jclass cls, jint ind)
{
SDL_CustomApplicationMain(ind);
int val = SDL_Init(ind);
return val;
}

You can’t call that code directly, it needs to be modified. The code
in CustomApplicationMain() will not work as written in SDLMain.m.

Here is the code i am referring to:

void CustomApplicationMain (argc, argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;

/* Ensure the application object is initialised */
[SDLApplication sharedApplication];

#ifdef SDL_USE_CPS
{
CPSProcessSerNum PSN;
/* Tell the dock about us /
if (!CPSGetCurrentProcess(&PSN))
if
(!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
[SDLApplication sharedApplication];
}
#endif /
SDL_USE_CPS */

/* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]];
setupAppleMenu();
setupWindowMenu();

/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];

/* Start the main event loop */
[NSApp run];

[sdlMain release];
[pool release];

}

You could include all of that code in Main.c. But you would have to
copy other code from SDLMain.m as well (setupAppleMenu(),
setupWindowMenu(), etc). Also, you cannot call [ NSApp run] or the
releases following that. [ NSApp run ] does not return until the
application exits.

If you don’t want all that code, I think the minimum you need is this.

#import <Cocoa/Cocoa.h>

JNIEXPORT jint JNICALL Java_sdl_core_Main_SDLInit (JNIEnv * env,
jclass cls, jint ind)
{

 NSAutoreleasePool  *pool = [[NSAutoreleasePool alloc] init];

[ NSApplication sharedApplication ];

int val  = SDL_Init(ind);
return val;

}

my make command:

gcc -DUSING_GCC -framework Cocoa -framework Foundation -framework
JavaVM -framework SDL -framework SDL_image
-I/Users/bsugar/Library/Frameworks/SDL.framework/Versions/A/Headers
-I/Users/bsugar/Library/Frameworks/SDL_image.framework/Versions/A/
Headers -I/System/Library/Frameworks/JavaVM.framework/Headers/
-I/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
-c sdl/jni/*.c
gcc -DUSING_GCC -framework Cocoa -framework Foundation -framework
JavaVM -framework SDL -framework SDL_image
-I/Users/bsugar/Library/Frameworks/SDL.framework/Versions/A/Headers
-I/Users/bsugar/Library/Frameworks/SDL_image.framework/Versions/A/
Headers -I/System/Library/Frameworks/JavaVM.framework/Headers/
-I/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
-bundle -o libSDL4Java.jnilib *.o
ld: warning multiple definitions of symbol _GetPixel
SFont.o definition of _GetPixel in section (__TEXT,__text)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/QD.framework/Versions/A/QD(QD.o) definition of _GetPixel
ld: warning multiple definitions of symbol _TextWidth
SFont.o definition of _TextWidth in section (__TEXT,__text)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/QD.framework/Versions/A/QD(QD.o) definition of _TextWidth
ld: Undefined symbols:
_SDL_CustomApplicationMain
make: *** [jni] Error 1

Note you’ll have to pass “-x objective-c” and “-lobjc” when in the
step you have shown above.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

almost there, i believe. i can get a sdl window to come up with my
application in it! However i can not make that window active i just
have a spinning cursor when i am over it. What I missing from below?

JNIEXPORT jint JNICALL Java_sdl_core_Main_SDLInit (JNIEnv * env, jclass
cls, jint ind)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[ NSApplication sharedApplication ];
[ NSApp setMainMenu:[[NSMenu alloc] init] ];
[ pool release ];
int val = SDL_Init(ind);
return val;
}

Try using the CPS* functions, as shown in CustomApplicationMain. Also,
don’t call [ pool release ] here, the autorelease pool must persist
until the application exits.On Friday, November 8, 2002, at 08:37 AM, Brian Sugar wrote:

almost there, i believe. i can get a sdl window to come up with my
application in it! However i can not make that window active i just
have a spinning cursor when i am over it. What I missing from below?

JNIEXPORT jint JNICALL Java_sdl_core_Main_SDLInit (JNIEnv * env,
jclass cls, jint ind)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[ NSApplication sharedApplication ];
[ NSApp setMainMenu:[[NSMenu alloc] init] ];
[ pool release ];
int val = SDL_Init(ind);
return val;
}


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl