Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DvDevice setDisabled doesn't work in Java
09-12-2011, 11:24 AM
Post: #1
DvDevice setDisabled doesn't work in Java
There's a problem in the JNI code that stops DvDevice.setDisabled() from working in Java. In the file Bindings/Java/DvDevice.c, line 150 is

DvDeviceSetDisabled(device, callback, &ref);

This should be

DvDeviceSetDisabled(device, callback, ref);

as it is in other similar code that sets up a callback for later invocation.

Passing this incorrect value causes an access violation when the callback is invoked (at line 22 of the same file).

Simon
Find all posts by this user
09-12-2011, 11:46 AM
Post: #2
RE: DvDevice setDisabled doesn't work in Java
(09-12-2011 11:24 AM)simoncn Wrote:  There's a problem in the JNI code that stops DvDevice.setDisabled() from working in Java.

Thanks for this. I've applied your suggested fix locally so it'll hopefully be on github this evening.
Find all posts by this user
09-12-2011, 12:59 PM
Post: #3
RE: DvDevice setDisabled doesn't work in Java
(09-12-2011 11:46 AM)simonc Wrote:  Thanks for this. I've applied your suggested fix locally so it'll hopefully be on github this evening.

Thanks. I discovered another problem in the same area. In lines 45-49 of DvDevice.c, the call to DeleteGlobalRef() is made after the call to DetachCurrentThread(). This doesn't work, because the JVM doesn't allow a DeleteGlobalRef() call from a thread that isn't currently attached. The fix is to switch the order of these calls, as follows:

(*env)->CallVoidMethod(env, ref->callbackObj, mid);

(*env)->DeleteGlobalRef(env, ref->callbackObj);
if(attached < 0)
{
(*(ref->vm))->DetachCurrentThread(ref->vm);
}
free(ref);
Find all posts by this user
09-12-2011, 01:08 PM
Post: #4
RE: DvDevice setDisabled doesn't work in Java
(09-12-2011 12:59 PM)simoncn Wrote:  
(09-12-2011 11:46 AM)simonc Wrote:  Thanks for this. I've applied your suggested fix locally so it'll hopefully be on github this evening.

Thanks. I discovered another problem in the same area.

Thanks. I've applied this too.

The earlier Java fix plus other pending changes are now available. This last one should appear this evening.
Find all posts by this user
09-12-2011, 04:15 PM
Post: #5
RE: DvDevice setDisabled doesn't work in Java
On to the next problem Sad and this one's got me rather stumped Huh

After calling DvDevice.setDisabled(), my callback's deviceDisabled() method is now running successfully. However, I'm getting an ohNet runtime error popup that says:

Debug Error!
Program: C:\Windows\system32\java.exe
Module: F:\testserver\bin\ohNet.dll
File f:\git\ohnet\build\include\openhome\functor.h
Line: 87

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually the result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Here's the stack trace:

> ohNet.dll!OpenHome::MemberTranslatorC::Thunk(const OpenHome::Functor & aFb) Line 88 C++
ohNet.dll!OpenHome::Functor::operator()() Line 34 + 0x1d bytes C++
ohNet.dll!OpenHome::Net::DviDevice::ProtocolDisabled() Line 374 C++
ohNet.dll!OpenHome::MemberTranslator<OpenHome::Net::DviDevice,void (__thiscall OpenHome::Net::DviDevice::*)(void)>::Thunk(const OpenHome::Functor & aFb) Line 76 + 0x12 bytes C++
ohNet.dll!OpenHome::Functor::operator()() Line 34 + 0x1d bytes C++
ohNet.dll!OpenHome::Net::DviProtocolUpnp::SubnetDisabled() Line 428 C++
ohNet.dll!OpenHome::MemberTranslator<OpenHome::Net::DviProtocolUpnp,void (__thiscall OpenHome::Net::DviProtocolUpnp::*)(void)>::Thunk(const OpenHome::Functor & aFb) Line 76 + 0x12 bytes C++
ohNet.dll!OpenHome::Functor::operator()() Line 34 + 0x1d bytes C++
ohNet.dll!OpenHome::Net::DviMsgNotify::NextMsg() Line 1479 C++
ohNet.dll!OpenHome::Net::DviMsgScheduler::NextMsg() Line 1263 + 0x1e bytes C++
ohNet.dll!OpenHome::MemberTranslator<OpenHome::Net::DviMsgScheduler,void (__thiscall OpenHome::Net::DviMsgScheduler::*)(void)>::Thunk(const OpenHome::Functor & aFb) Line 76 + 0xc bytes C++
ohNet.dll!OpenHome::Functor::operator()() Line 34 + 0x1d bytes C++
ohNet.dll!OpenHome::TimerManager::Fire() Line 226 C++
ohNet.dll!OpenHome::TimerManager::Run() Line 251 C++
ohNet.dll!OpenHome::MemberTranslator<OpenHome::TimerManager,void (__thiscall OpenHome::TimerManager::*)(void)>::Thunk(const OpenHome::Functor & aFb) Line 76 + 0x12 bytes C++
ohNet.dll!OpenHome::Functor::operator()() Line 34 + 0x1d bytes C++
ohNet.dll!OpenHome::ThreadFunctor::Run() Line 322 C++
ohNet.dll!OpenHome::Thread::EntryPoint(void * aArg) Line 197 + 0xf bytes C++
ohNet.dll!threadEntrypoint(void * aArg) Line 333 + 0x11 bytes C
kernel32.dll!773aed6c()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!776337f5()
ntdll.dll!776337c8()
Find all posts by this user
09-12-2011, 05:03 PM (This post was last modified: 09-12-2011 05:40 PM by simonc.)
Post: #6
RE: DvDevice setDisabled doesn't work in Java
(09-12-2011 04:15 PM)simoncn Wrote:  Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually the result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Windows has two calling conventions - stdcall and cdecl. Native builds use cdecl by default; Java expects JNI code to use stdcall.

ohNet C bindings are typically sympathetic to this by explicitly specifying __stdcall (actually STDCALL which pre-processes to nothing for Linux builds) in their declarations. I expect the problem will be a missing STDCALL in either an ohNet C binding or JNI function pointer.

The problem looks to be with the callback used to signal that SetDisable on a DvDevice has completed. Do you wait for this callback to run during your shutdown?
(09-12-2011 05:03 PM)simonc Wrote:  [quote='simoncn' pid='669' dateline='1323447301']

The problem looks to be with the callback used to signal that SetDisable on a DvDevice has completed. Do you wait for this callback to run during your shutdown?

I've hopefully fixed this. All being well, the code will be available in a couple of hours
Find all posts by this user
19-12-2011, 04:07 PM
Post: #7
RE: DvDevice setDisabled doesn't work in Java
This is working fine now with the 0.76 binary download. Thanks!
Find all posts by this user


Forum Jump: