Canister trapped: table out of bounds

I am facing an issue that i don’t fully understand. When i try to init a variable in a seperate canister call, the code breaks. I traced the code down to "FieldPlayerMLP.cpp ln 37.
If i uncomment //g_PitchManager = new PitchManager(); in play_match in SimSoccerServer.cpp, the code works fine.
Here are the steps to reproduce the issue:

  1. clear && icpp build-wasm --config=icpp_libraries.toml && wasm2wat build/SimSoccerServer.wasm --output=build/SimSoccerServer.wasm.wat
  2. Open SimSoccerServer.wasm.wat in Notepad++
  3. Mark all lines that start with export
  4. Find start_match & play_match and remove bookmark for their export
  5. Search/Bookmark/Remove Bookmarked Lines then save
  6. wat2wasm build/SimSoccerServer.wasm.wat --output=build/SimSoccerServer_noexports.wasm && …/binaryen/bin/wasm-opt build/SimSoccerServer_noexports.wasm -o build/SimSoccerServer.wasm -Oz --enable-bulk-memory && dfx deploy
  7. dfx canister --network local call SimSoccerServer start_match
  8. dfx canister --network local call SimSoccerServer play_match ‘(1674211940: nat64)’

Repo Link:

It seems that even calling start_match twice, which does nothing, gives the same error. Totally lost on what this error refers to!

I have more time to play around with this tomorrow. As a start, if PitchManager is causing you issues, have you taken a look at all of the times that you called an index in PitchManager.cpp?

I have tried removing all code related to PitchManager, basically making the canister call doing nothing, yet I still get the same error on the second canister call of the same function (start_match).

1 Like

Figured the issue. Link flags needed to be configured differently.
Following flag removed:
-nostartfiles
Following flag added:
-mexec-model=reactor

Thanks a lot @jennifertran

1 Like

Do you know why this would result in a table out of bounds error?

Not sure how those flags affect the code generated exactly to cause this error.