Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JNI problem  (Read 1474 times)
0 Members and 1 Guest are viewing this topic.
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Posted 2005-08-27 22:36:09 »

Hi

I've spent all day trying to find the bug in the linux ff code. The symptom is that each time the code is started, an event is uploaded to the device. The problem is, that the device I have can hold 8 events, and each time I run it, it doesn't clear the old ones out.

I've written some test java code, that uses the same interface as jinput does, but this code doesn't have the same issue. I have noticed a couple of things during the development of the new native interface and test code.

not doing a 'free' in the native code of the device node I'm using, seems to always cause the issue. adding this free seemed to fix the tests.

So i'm thinking that there are some references to objects or structs or something that the java code keeps alive some how. If I don't specifically call the free by calling a dispose methed from the java side, then it always appens.

I've created a branch in CVS for the linux plugin dir and below, called forcefeedback, that contains the current work.

I'm most confused and admit that JNI is not my strong point.

Endolf

Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2005-08-28 00:26:49 »

Well, im n ot sure Im following BUT

If you are counting on finalizers, then don't because you can't.  There is no gaurantee when if ever a given finalizer will get run.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #2 - Posted 2005-08-28 08:50:51 »

Hi

Nope, ran in to that one early on in my career Smiley.

I'm using a shutdown hook on each rumbler to go through and clean it up, I can see them being called. They call the same code as my test class, which is puzzling, I can only assume that the plugin has hold of some other resource that the tests don't use.

Endolf

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #3 - Posted 2005-08-28 12:22:23 »

Hi

Ok, further information.

I've added a shutdown hook to the LinuxEnvironmentPlugin that calls a public static method on itself that runs through the native interface closing all the controllers.

This runs happily, but doesn't solve the problem.

When I call the method myself, from my test class on shutdown, it works fine. There appears to be some difference in the way that calling this shutdown happens depending on wether it's a shutdown hook or the main method. The only thing I can think of is that it's to do with the different threads.

I tried this by then calling the method from another thread in my test app, and it did indeed break it. So. It seems that I can't use a shutdown hook to do it. Any other ideas?

Is there something I should be doing to tell the JVM to free all the memory that the libraries it has opened are using?

I'm thinking that there is a memory leak (although I can't find it) in the lib/jni/java interface that is holding on to the event structure. So when the app quits, it's left around and the device still has it. If I call my own cleanup from the thread that created it, then it seems to clear fine, but I call my clear up from some other thread, then it hangs around.

Endolf

Offline kevglass

« JGO Spiffy Duke »


Medals: 221
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #4 - Posted 2005-08-29 13:20:02 »

Is the event object native or java side? If native, is it an object or a structure?

Kev

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #5 - Posted 2005-08-29 14:14:56 »

Hi

It's a struct in the native code, not a pointer to one.

Endolf

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #6 - Posted 2005-08-29 16:35:06 »

Hi

Right, ok, this is wierd, although the native stuff is in a shared lib, the java thread you call the methods from seems to effect things. For example, if I init the event interface layer from one thread, I also have to call the rumble methods from that same java thread, otherwise I get a permission denied error. If I call my cleanup code, it leaves effects in the device memory.

I've only made modifications to the event interface layer, not the joystick layer, so USB devices work now, but there is no support for the old 15 pin style devices. The outcome of the poll will decide if I need to do more work to get them both working, or if I just merge in the stuff I have.

Endolf

Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2005-08-29 23:52:31 »

Hi

Right, ok, this is wierd, although the native stuff is in a shared lib, the java thread you call the methods from seems to effect things. For example, if I init the event interface layer from one thread, I also have to call the rumble methods from that same java thread, otherwise I get a permission denied error. If I call my cleanup code, it leaves effects in the device memory.
f

Hmm, this sounds like very Linux specific behavior and I'm afraid I can't help much :/

if it were Windows I'd slap you for tring to do anything that calls DX fromdifferent threads, WIndows hates that.  (Its still a monothreaded operating system, it just prentends on the suer level that it isn't.)

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (6 views)
2014-12-27 04:03:04

TheDudeFromCI (12 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (83 views)
2014-12-05 12:39:02

SHC (94 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!