It looks like ConnectBlock is passing a pointer to the current block index to GetBlockValue.
CreateNewBlock is passing a pointer to the previous block index to GetBlockValue.
This is causing them to generate different coinbase amounts, and ConnectBlock is rejecting the block created by CreateNewBlock.