Re: [sdljava-users] JNI pitfall
Status: Beta
Brought to you by:
ivan_ganza
From: Ivan Z. G. <iva...@ya...> - 2005-03-06 01:21:13
|
Thanks for this info. Once I get a FAQ going I'll be certain to mention it there. This is making me think that inside SDLMixer we might want to keep a reference to whatever is being played until its finished playing. Once you say playMusic and pass in the song we shouldn't allow the garbage collector to scoop it up. I think this could happen once the callbacks are implemented. Any suggestions appreciated... -Ivan/ Robert Schuster wrote: > Hi list, > I was writing on a small demo app which at some place included these > lines: > > if (!measureFPS) { > SDLMixer.openAudio(44100, SDLMixer.AUDIO_S16SYS, 2, 2048); > > System.out.println("Loading song."); > > MixMusic song = SDLMixer.loadMUS(Thread.currentThread() > .getContextClassLoader() > .getResourceAsStream("memesong.ogg")); > > System.out.println("Playing song: " + song); > SDLMixer.playMusic(song, 0); > } > > The code does not look very special but at runtime something odd will > happen: You will hear a small bit of music and then it stops. The > reason for this is that the MixMusic instance 'song' gets garbage > collected when the if-block ends. I describe this here because this > behavior is caused by the way Swig handles native pointers and can be > a pitfall for others as it was for me. > > You can work around this problem by assigning an instance like > MixMusic (which in the above example is a local variable) to an > instance or class variable. > > @Ivan: If you are going to write a FAQ for SDLJava sometime it would > be good to add this issue to it. > > cu > Robert > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > sdljava-users mailing list > sdl...@li... > https://lists.sourceforge.net/lists/listinfo/sdljava-users |