New CppInterface callback problem
Posted: 23 Apr 2011, 10:53
Hi,
I'm trying to code a simple threaded(boost) ai with the new Cpp interface (using the sample CCppTestAI from the git master)
(I'm new to C++ normaly I code in C/C99)
My Problem is that I cant use the callback outside of the cpptestai::CCppTestAI::HandleEvent function.
I tried to use it out of a boost::thread, from an external class,function,inside the handleevent but with another function. Nothing works!
the following two calls are working fine in HandleEvent (from cpptestai::CCppTestAI)
if the folowing function get called from HandleEvent the game does a hangup.
Hangup:
the following boost thread produces a SIGSEGV (it does the same not threaded)
so every time I try to use callback out of the HandleEvent function the game crashes.
Can anyone please tell me how to use the callback correctly outside the HandleEvent (from a thread?) ?
I'm trying to code a simple threaded(boost) ai with the new Cpp interface (using the sample CCppTestAI from the git master)
(I'm new to C++ normaly I code in C/C99)
My Problem is that I cant use the callback outside of the cpptestai::CCppTestAI::HandleEvent function.
I tried to use it out of a boost::thread, from an external class,function,inside the handleevent but with another function. Nothing works!
the following two calls are working fine in HandleEvent (from cpptestai::CCppTestAI)
Code: Select all
callback->GetGame()->SendTextMessage(msgText.c_str(), 0);
callback->GetGame()->SendTextMessage("TICK2", 0);
Code: Select all
void K01AIn::K01AIc::WriteChat(const char* msg)//I renamed cpptestai::CCppTestAI
{
callback->GetGame()->SendTextMessage(msg, 0);
}
Code: Select all
[f=0000000] <SkirmishAI: K01 0.1 (team 1)>: HI IM 1
[f=0000000] <SkirmishAI: K01 0.1 (team 1)>: Hello Engine (from CppTestA), num my unitZ is 1, first friendly units def name is: corcom
[f=0000000] <SkirmishAI: K01 0.1 (team 1)>: TICK2
[f=0000000] <SkirmishAI: K01 0.1 (team 1)>: whoo
[f=0000001] Skirmish AI "Enemy" (ID:0, Short-Name:"K01", Version:"0.1") took over control of team 1
spring: malloc.c:4631: _int_malloc: Assertion `(unsigned long)(size) >= (unsigned long)(nb)' failed.
[f=0000004] Aborted (SIGABRT) in spring 0.82+.4.0
[f=0000004] Stacktrace:
[f=0000004] [Watchdog] Hang detection triggered for Spring 0.82+.4.0.
[f=0000004] (in thread: audio)
[f=0000004] (in thread: main)
[f=0000004] Stacktrace (audio):
[f=0000004] No Stacktraces for non-MainThread.
[f=0000004] Stacktrace (main):
[f=0000004] (Note: This stacktrace is not 100% accurate! It just gives an impression.)
zsh: killed /usr/local/bin/spring //I did a SIGKILL, because spring din't response to a SIGTERM
Code: Select all
void testthread()
{
boost::posix_time::seconds workTime(1);
for(;;)
{
springai::OOAICallback* caback;
caback->GetGame()->SendTextMessage("TICK5", 0);
K01AI->WriteChat("TICK6");//K01AI is the cpptestai::CCppTestAI* ai object created in AIExport.cpp
boost::this_thread::sleep(workTime);
}
}
Code: Select all
[f=0000000] Connection attempt from UnnamedPlayer
[f=0000000] -> Version: 0.82+.4.0
[f=0000000] -> Connection established (given id 0)
[f=0000000] Player UnnamedPlayer finished loading and is now ingame
[f=0000000] GameID: 548fb24d84d10af1eeba4b9e1cdf4421
[f=0000000] UnnamedPlayer added point: Start 0
[f=0000000] <SkirmishAI: K01 0.1 (team 1)>: HI IM 1
[f=0000000] <SkirmishAI: K01 0.1 (team 1)>: Hello Engine (from CppTestA), num my unitZ is 1, first friendly units def name is: corcom
[f=0000000] <SkirmishAI: K01 0.1 (team 1)>: TICK2
[f=0000001] Skirmish AI "Enemy" (ID:0, Short-Name:"K01", Version:"0.1") took over control of team 1
[f=0000004] Segmentation fault (SIGSEGV) in spring 0.82+.4.0
[f=0000004] Stacktrace:
[f=0000004] This stack trace indicates a problem with a Skirmish AI library.
[f=0000007] <0> /lib/libc.so.6(+0x34780) [0x7fd79f858780]
[f=0000007] <1> /spring/spring/AI/Skirmish/K01/src/CppTestAI.cpp:102
[f=0000007] <2> /usr/lib/libboost_thread.so.1.46.0(thread_proxy+0x6c) [0x7fd7a144832c]
[f=0000007] <3> /usr/lib64/libGL.so.1(+0x9e853) [0x7fd7a2bfc853]
*** glibc detected *** /usr/local/bin/spring: realloc(): invalid next size: 0x000000000b0cfde0 ***
======= Backtrace: =========
/lib/libc.so.6(+0x7342a)[0x7fd79f89742a]
/lib/libc.so.6(+0x75ee7)[0x7fd79f899ee7]
/lib/libc.so.6(realloc+0xf9)[0x7fd79f89b479]
/usr/lib64/libGL.so.1(+0x9f74d)[0x7fd7a2bfd74d]
======= Memory map: ========
00400000-00d99000 r-xp 00000000 08:01 4061114 /usr/local/bin/spring
00f98000-00f9e000 rw-p 00998000 08:01 4061114 /usr/local/bin/spring
00f9e000-01fdc000 rw-p 00000000 00:00 0
02578000-0cc87000 rw-p 00000000 00:00 0 [heap]
40192000-40209000 rw-p 00000000 00:00 0
41c31000-41c33000 r-xs 00000000 08:01 15885642 /tmp/glGiofLx (deleted)
7fd777d80000-7fd777f80000 rw-s bf3c9000 00:0c 6713 /dev/nvidia0
7fd778000000-7fd77b50d000 rw-p 00000000 00:00 0
7fd77b50d000-7fd77c000000 ---p 00000000 00:00 0
7fd77c059000-7fd77fe0c000 rw-p 00000000 00:00 0
7fd77fe0c000-7fd77fe0d000 ---p 00000000 00:00 0
7fd77fe0d000-7fd78060d000 rw-p 00000000 00:00 0
7fd78060d000-7fd78060e000 ---p 00000000 00:00 0
7fd78060e000-7fd780e0e000 rw-p 00000000 00:00 0
7fd781659000-7fd7835db000 rw-p 00000000 00:00 0
7fd7836db000-7fd7836dc000 ---p 00000000 00:00 0
7fd7836dc000-7fd783edc000 rw-p 00000000 00:00 0
7fd783edc000-7fd7840dc000 rw-s 0c61d000 00:0c 6713 /dev/nvidia0
7fd7840dc000-7fd7840dd000 ---p 00000000 00:00 0
7fd7840dd000-7fd7848dd000 rw-p 00000000 00:00 0
7fd7848dd000-7fd7848e8000 r-xp 00000000 08:01 11641153 /lib/libnss_files-2.13.so
7fd7848e8000-7fd784ae7000 ---p 0000b000 08:01 11641153 /lib/libnss_files-2.13.so
7fd784ae7000-7fd784ae8000 r--p 0000a000 08:01 11641153 /lib/libnss_files-2.13.so
7fd784ae8000-7fd784ae9000 rw-p 0000b000 08:01 11641153 /lib/libnss_files-2.13.so
7fd784ae9000-7fd784bd3000 r-xp 00000000 08:01 4178519 /usr/lib/libasound.so.2.0.0
7fd784bd3000-7fd784dd2000 ---p 000ea000 08:01 4178519 /usr/lib/libasound.so.2.0.0
7fd784dd2000-7fd784dda000 rw-p 000e9000 08:01 4178519 /usr/lib/libasound.so.2.0.0
7fd784e0f000-7fd784e10000 ---p 00000000 00:00 0
7fd784e10000-7fd785610000 rw-p 00000000 00:00 0
7fd785610000-7fd785614000 r-xp 00000000 08:01 11640954 /lib/libattr.so.1.1.0
7fd785614000-7fd785813000 ---p 00004000 08:01 11640954 /lib/libattr.so.1.1.0
7fd785813000-7fd785814000 rw-p 00003000 08:01 11640954 /lib/libattr.so.1.1.0
7fd785814000-7fd785827000 r-xp 00000000 08:01 11641134 /lib/libresolv-2.13.so
7fd785827000-7fd785a27000 ---p 00013000 08:01 11641134 /lib/libresolv-2.13.so
7fd785a27000-7fd785a28000 r--p 00013000 08:01 11641134 /lib/libresolv-2.13.so
7fd785a28000-7fd785a29000 rw-p 00014000 08:01 11641134 /lib/libresolv-2.13.so
7fd785a29000-7fd785a2b000 rw-p 00000000 00:00 0
7fd785a2b000-7fd785cde000 r-xp 00000000 08:01 4178541 /usr/lib/libvorbisenc.so.2.0.8
7fd785cde000-7fd785edd000 ---p 002b3000 08:01 4178541 /usr/lib/libvorbisenc.so.2.0.8
7fd785edd000-7fd785ef9000 rw-p 002b2000 08:01 4178541 /usr/lib/libvorbisenc.so.2.0.8
7fd785ef9000-7fd785f43000 r-xp 00000000 08:01 4178537 /usr/lib/libFLAC.so.8.2.0
7fd785f43000-7fd786143000 ---p 0004a000 08:01 4178537 /usr/lib/libFLAC.so.8.2.0
7fd786143000-7fd786145000 rw-p 0004a000 08:01 4178537 /usr/lib/libFLAC.so.8.2.0
7fd786145000-7fd78615a000 r-xp 00000000 08:01 11641028 /lib/libnsl-2.13.so
7fd78615a000-7fd786359000 ---p 00015000 08:01 11641028 /lib/libnsl-2.13.so
7fd786359000-7fd78635a000 r--p 00014000 08:01 11641028 /lib/libnsl-2.13.so
7fd78635a000-7fd78635b000 rw-p 00015000 08:01 11641028 /lib/libnsl-2.13.so
7fd78635b000-7fd78635d000 rw-p 00000000 00:00 0
7fd78635d000-7fd786361000 r-xp 00000000 08:01 11641034 /lib/libcap.so.2.20
7fd786361000-7fd786560000 ---p 00004000 08:01 11641034 /lib/libcap.so.2.20
7fd786560000-7fd786561000 rw-p 00003000 08:01 11641034 /lib/libcap.so.2.20
7fd786561000-7fd7865a4000 r-xp 00000000 08:01 4185074 /usr/lib/libdbus-1.so.3.5.3
7fd7865a4000-7fd7867a4000 ---p 00043000 08:01 4185074 /usr/lib/libdbus-1.so.3.5.3
7fd7867a4000-7fd7867a5000 r--p 00043000 08:01 4185074 /usr/lib/libdbus-1.so.3.5.3
7fd7867a5000-7fd7867a6000 rw-p 00044000 08:01 4185074 /usr/lib/libdbus-1.so.3.5.3
7fd7867a6000-7fd7867ab000 r-xp 00000000 08:01 4180172 /usr/lib/libasyncns.so.0.3.1
7fd7867ab000-7fd7869aa000 ---p 00005000 08:01 4180172 /usr/lib/libasyncns.so.0.3.1
7fd7869aa000-7fd7869ab000 rw-p 00004000 08:01 4180172 /usr/lib/libasyncns.so.0.3.1
7fd7869ab000-7fd786a0b000 r-xp 00000000 08:01 4180526 /usr/lib/libsndfile.so.1.0.24
7fd786a0b000-7fd786c0b000 ---p 00060000 08:01 4180526 /usr/lib/libsndfile.so.1.0.24
7fd786c0b000-7fd786c0e000 rw-p 00060000 08:01 4180526 /usr/lib/libsndfile.so.1.0.24
7fd786c0e000-7fd786c12000 rw-p 00000000 00:00 0
7fd786c12000-7fd786c1a000 r-xp 00000000 08:01 4228497 /usr/lib/libwrap.so.0.7.6
7fd786c1a000-7fd786e19000 ---p 00008000 08:01 4228497 /usr/lib/libwrap.so.0.7.6
7fd786e19000-7fd786e1b000 rw-p 00007000 08:01 4228497 /usr/lib/libwrap.so.0.7.6
7fd786e1b000-7fd786e1e000 r-xp 00000000 08:01 4178661 /usr/lib/libxcb-atom.so.1.0.0
7fd786e1e000-7fd78701e000 ---p 00003000 08:01 4178661 /usr/lib/libxcb-atom.so.1.0.0
7fd78701e000-7fd78701f000 rw-p 00003000 08:01 4178661 /usr/lib/libxcb-atom.so.1.0.0
7fd78701f000-7fd787024000 r-xp 00000000 08:01 4179071 /usr/lib/libXtst.so.6.1.0
7fd787024000-7fd787224000 ---p 00005000 08:01 4179071 /usr/lib/libXtst.so.6.1.0
7fd787224000-7fd787225000 rw-p 00005000 08:01 4179071 /usr/lib/libXtst.so.6.1.0
7fd787225000-7fd787226000 r-xp 00000000 08:01 4179619 /usr/lib/libX11-xcb.so.1.0.0
7fd787226000-7fd787425000 ---p 00001000 08:01 4179619 /usr/lib/libX11-xcb.so.1.0.0
7fd787425000-7fd787426000 rw-p 00000000 08:01 4179619 /usr/lib/libX11-xcb.so.1.0.0[f=0000007] Aborted (SIGABRT) in spring 0.82+.4.0
[f=0000007] Stacktrace:
[f=0000007] [Watchdog] Hang detection triggered for Spring 0.82+.4.0.
[f=0000007] (in thread: main)
[f=0000007] Stacktrace (main):
[f=0000007] (Note: This stacktrace is not 100% accurate! It just gives an impression.)
zsh: killed /usr/local/bin/spring
Can anyone please tell me how to use the callback correctly outside the HandleEvent (from a thread?) ?