Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Fix HanabiState.copy setting a bad pointer for _game member #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*.pyc
*.pyc
Makefile
CMakeFiles/
CMakeCache.txt
*.cmake
9 changes: 5 additions & 4 deletions hanabi_learning_environment/pyhanabi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,13 @@ void DeleteState(pyhanabi_state_t* state) {
state->state = nullptr;
}

const void* StateParentGame(pyhanabi_state_t* state) {
void StateParentGame(pyhanabi_state_t* state, pyhanabi_game_t* game) {
REQUIRE(state != nullptr);
REQUIRE(state->state != nullptr);
return static_cast<const void*>(
reinterpret_cast<hanabi_learning_env::HanabiState*>(state->state)
->ParentGame());
REQUIRE(game != nullptr);
auto hanabi_state =
reinterpret_cast<hanabi_learning_env::HanabiState*>(state->state);
game->game = (void*)hanabi_state->ParentGame();
}

void StateApplyMove(pyhanabi_state_t* state, pyhanabi_move_t* move) {
Expand Down
2 changes: 1 addition & 1 deletion hanabi_learning_environment/pyhanabi.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int HistoryItemDealToPlayer(pyhanabi_history_item_t* item);
void NewState(pyhanabi_game_t* game, pyhanabi_state_t* state);
void CopyState(const pyhanabi_state_t* src, pyhanabi_state_t* dest);
void DeleteState(pyhanabi_state_t* state);
const void* StateParentGame(pyhanabi_state_t* state);
void StateParentGame(pyhanabi_state_t* state, pyhanabi_game_t* game);
void StateApplyMove(pyhanabi_state_t* state, pyhanabi_move_t* move);
int StateCurPlayer(pyhanabi_state_t* state);
void StateDealRandomCard(pyhanabi_state_t* state);
Expand Down
5 changes: 3 additions & 2 deletions hanabi_learning_environment/pyhanabi.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def try_cdef(header=PYHANABI_HEADER, prefixes=DEFAULT_CDEF_PREFIXES):
cdef_string = cdef_string + line + "\n"
ffi.cdef(cdef_string)
cdef_loaded_flag = True
return True
return True
except IOError:
pass
return False
Expand Down Expand Up @@ -516,7 +516,8 @@ def __init__(self, game, c_state=None):
self._game = game.c_game
lib.NewState(self._game, self._state)
else:
self._game = lib.StateParentGame(c_state)
self._game = ffi.new("pyhanabi_game_t*")
lib.StateParentGame(c_state, self._game)
lib.CopyState(c_state, self._state)

def copy(self):
Expand Down