Piasy
01/27/2020, 12:19 PMkotlin.native.initRuntimeIfNeeded() in my kotlin code before I connect to server, but it still crash my program. If I fire the callback on main thread, e.g. APP C++ code calls kotlinTestFunc , which calls cppSocketIOConnect , and fire the callback directly inside cppSocketIOConnect , it works fine.
Do I miss something?Artyom Degtyarev [JB]
01/27/2020, 12:28 PMPiasy
01/27/2020, 12:37 PMException thrown at 0x004FEFB0 in WindowsExample.exe: 0xC0000005: Access violation executing location 0x004FEFB0.
I write it to crash dump and analyze it with dbghelper, but the stack also doesn't give helpful message, the attachment is the full analyze output.Piasy
01/27/2020, 12:47 PMPiasy
01/27/2020, 12:55 PMvoid SioOn(void* sio, SIOListener2 listener) {
reinterpret_cast<sio::client*>(sio)->set_socket_open_listener(
[=](std::string const& nsp) {
listener();
});
}
Previously I capture it by reference [&] .Piasy
01/27/2020, 1:16 PM.pdb when compile kotlin code to .dll on windows? @Artyom Degtyarev [JB]Artyom Degtyarev [JB]
01/27/2020, 1:40 PMPiasy
01/27/2020, 1:41 PMPiasy
01/27/2020, 2:01 PMInt in kotlin code, my program crashed with error: Exception thrown at 0x6514A0E9 (AvConf.dll) in WindowsExample.exe: 0xC0000005: Access violation reading location 0x00000020. if I don't access the integer, it works fine, if I fire the callback directly in main thread, it also works fine.Artyom Degtyarev [JB]
01/27/2020, 2:15 PMStableRef to the callback or it is a C++ int that the Kotlin function takes as input?Piasy
01/27/2020, 2:28 PMint that the Kotlin function takes as input.
Here is my C++ code:
typedef void(*SIOListener)(int);
void SioOn(void* sio, const char* event, SIOListener listener) {
reinterpret_cast<sio::client*>(sio)->set_socket_open_listener(
[=](std::string const& nsp) {
listener(0);
});
}
Here is my kotlin code:
private fun SioListenerFunction2(len: Int) {
Logging.error("SIO", "SioListenerFunction2")
Logging.error("SIO", "len $len")
}
NKBundle.SioOn(socket, event, staticCFunction(::SioListenerFunction2))
If I don't log len param, or if I invoke listener directly, it works fine.Piasy
01/27/2020, 2:30 PMsocket variable is created by a C++ function, so don't worry about it.Artyom Degtyarev [JB]
01/27/2020, 2:42 PMinitRuntimeIfNeeded() here, before logging.Artyom Degtyarev [JB]
01/27/2020, 2:55 PM[=](std::string const& nsp, int zero = 0) {
listener(zero);
}
, but it’s just a guess.Piasy
01/27/2020, 3:00 PMinitRuntimeIfNeeded() does the magic! So the note in C Interop page means it should be called inside the callback right?
And regarding your comment on C++ code, actually passing 0 back is only for test purpose, there shall be more data from C++, and the int is the length of an array.
Thank you very much!