bwapi / bwapi

Brood War API
http://bwapi.github.io/
GNU Lesser General Public License v3.0
1.6k stars 271 forks source link

Fix replay divide by 0 crashes on load #579

Open heinermann opened 9 years ago

heinermann commented 9 years ago

Here is a log of the crash.

//////////////////////////////////////////////////
TIME: Sun Apr 26 22:29:16 2015

VERSION: 1.16.1.1
BWAPI:
REVISION: 4630
BUILD: RELEASE
ERROR: Invalid_Parameter
LOCATION: Single Player Replay

EXCEPTION: 0xC0000094 EXCEPTION_INT_DIVIDE_BY_ZERO
FAULT: 0x00427ABF StarCraft.exe
REGISTERS:
EDI: 0000000A
ESI: 0828A4F6
EBX: 0828A144
EDX: 00000000
ECX: FFFFFFFF
EAX: 00000000
EBP: 0018FDFC
EIP: 00427ABF
ESP: 0018FDC8
STACK:
StarCraft.exe 0x00427ABF replayStatBtns
StarCraft.exe 0x00459AB3 updateCurrentButtonset
StarCraft.exe 0x004D940F updateHUDInformation
StarCraft.exe 0x004D998D BeginGame
StarCraft.exe 0x004E07FA preLoadGame
StarCraft.exe 0x004E0B20 WinMain(x,x,x,x)
StarCraft.exe 0x00404DA5 start
KERNEL32.DLL 0x76E27C04 BaseThreadInitThunk
ntdll.dll 0x776EAD1F RtlInitializeExceptionChain
ntdll.dll 0x776EACEA RtlInitializeExceptionChain

We try to prevent it by using the following workaround: https://github.com/bwapi/bwapi/blob/master/bwapi/BWAPI/Source/GameUpdate.cpp#L199-201 . This is supposed to prevent saving replays with a 0 frame time. However this is apparently insufficient, as this replay has surfaced.

The replay in question is this one: http://bots-stats.krasi0.com/replays/Bot2/2015%2004%2022/Python%201.1_PVST_215041_225280.rep

BoomerangAide commented 9 years ago

My guess would be that this replay try to do things (giving an order?) on frame 0 when the game expect it to be impossible (meaning there's no code against it) before frame 1, and thus some code would get executed too soon, and before GameImpl::update since the workaround fail.

If it's not that, I don't understand why in the workaround the condition is "!this->isReplay()" when the crash described by the log should only happen in replay (and the condition seems to be "not in replay"). But I'm a Starcraft modder, maybe I just don't understand how BWAPI work in this case.

heinermann commented 9 years ago

No, the issue is that it's writing the replay time (number of frames) as 0, so when it determines the progress bar % it divides by the maximum number of frames (which happens to be 0).