Blizzard / s2client-api

StarCraft II Client - C++ library supported on Windows, Linux and Mac designed for building scripted bots and research using the SC2API.
MIT License
1.66k stars 281 forks source link

Access Violation in sc2_client.cc GetObservation() #267

Open Frigerius opened 6 years ago

Frigerius commented 6 years ago

How to reproduce: Not sure. It occurres random. My setup: My Bot analyses Replays. My main program starts 4 independent threads with their own Coordinator and ReplayObserverBot. The replays are sorted into 4 different folders and each bot just takes the file from their specified folder. While running the program, the program randomly crashs. I figured out, that it crashes in ControlImp::GetObservation() in sc2_client.cc because GameResponsePtr response = WaitForResponse(); looks like returning null and std::cerr << "The main response is of type: " << std::to_string(response->response_case()) << std::endl; tries to access it. My current work around is to check if response is null, which seems to work, since I get this "Error in returning observation:" error string, but it doesn't crash anymore.

By following the method, in the endGameResponsePtr ProtoInterface::WaitForResponseInternal() initializes the object as null and returns null if there occurs a timeout, so I would guess it is related to this method (sc2_proto_interface.cc)

Here some logs, in this case the error occurred at the beginning: For each of my observations I rename the replays I already analyzed, so the error can be related to specif replays, BUT for my second run, I connected a debugger, which helped me to find the error and I was able to see which of my instances crashed and which replay it was using, so I tested this specific replay but it didn't crash, so its unlikely that this error just occurs on a specific file. (Replaced parts of the paths by "...")


Starting with version 4.3.1/
Launched SC2 (I:\...\Base65094\SC2_x64.exe), PID: 10640
Launched SC2 (I:\...\Base65094\SC2_x64.exe), PID: 14420
Launched SC2 (I:\...\Base65094\SC2_x64.exe), PID: 16168
Launched SC2 (I:\...\Base65094\SC2_x64.exe), PID: 11332
Waiting for connectionWaiting for connectionWaiting for connectionWaiting for connection
Connected to 127.0.0.1:
8128

Connected to 127.0.0.1:8428
Connected to 127.0.0.1:8228

Connected to 127.0.0.1:8328
Replaying: 'I:/.../Replays_0/54136c3f3c6683e28a795b644165f93e2a0b939b5920dd64962fb459ebe1faec.SC2Replay'
Replaying: 'I:/.../Replays_3/530ec41deb5ea75b1c2d57fb537467513c2967d91907bb8a0abecad1a7ef250a.SC2Replay'
Replaying: 'I:/.../Replays_1/527bca8906e524de8826546fb40c2c0ea4d1bd9d161f5abcbe4f5c1fc8dc94b3.SC2Replay'
Replaying: 'I:/.../Replays_2/5feb140421159ae1e61d277030d2210068cd7c079eef4225794da63080d03ce9.SC2Replay'
Replaying: 'I:/.../Replays_1/52663b7d48fbed8475e6223efc31bff1a28a746ffdd4ab5ca0c6d43e98da15be.SC2Replay'
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
WaitForReplay: start replay contains an error: 2
Replaying: 'I:/.../Replays_2/54361950d0a700770f613ab1e468457b199aa485ff5dd38cdabd5e3860b5ebd9.SC2Replay'
Replaying: 'I:/.../Replays_1/51dfb101c8cee78b157f5ec59a5df9ba64396c207fa17c046c0da5bee6ee17a4.SC2Replay'
Replaying: 'I:/.../Replays_0/53868de5d343ec0ea04d8690de060536b8da0059b0c047ae536f172c14af0248.SC2Replay'
Replaying: 'I:/.../Replays_3/52d9e6d825a68278c537eecaa8fad1e9dc31958f860d186032f9285aa7f0dcc3.SC2Replay'

Error in returning observation:   <------------ This line it would have been crashed, without my work around
Replaying: 'I:/.../Replays_2/53def364d701e30659be8314d4bcf3c44c5f847e5eb734e94e1db0f7c1505ff1.SC2Replay'
Replaying: 'I:/./Replays_1/5166b69fa450df3a918cd7a911b2ea7189d539a8bb9ee74250238cf3d408ebd8.SC2Replay'
Replaying: 'I:/./Replays_3/524361c5d946d55cff6656ccfb7e65267f9e25b5164cec3210de527a78bba8e0.SC2Replay'
Game application has been terminated due to unresponsiveness.
Launched SC2 (I:\...\Base65094\SC2_x64.exe), PID: 2412
Waiting for connection
Connected to 127.0.0.1:8129
Replaying: 'I:/.../Replays_0/531cbbea04fe212bf72be54198d9a4521ff4305fddd55afd08a0c45eb993e451.SC2Replay'```
Archiatrus commented 6 years ago

I also get this error "Error in returning observation:" sometimes. For me without apparent reason. I would say every 50 to 100 runs in the middle of a game. I run a bot playing the game and it uses the api in release mode.

LiliumAtratum commented 6 years ago

When I was trying to multithread my bot, issuing different commands to the sc2 API, it was crashing very fast. I suspect the API is not thread-safe?