-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demo crashes when entering the tunnel #90
Comments
I could reproduce an exception thrown by diff --git a/demo/include/utils/pacman_wrapper.hpp b/demo/include/utils/pacman_wrapper.hpp
index 9380637..0522eaf 100644
--- a/demo/include/utils/pacman_wrapper.hpp
+++ b/demo/include/utils/pacman_wrapper.hpp
@@ -30,7 +30,7 @@ public:
void printKeybindings();
private:
- void handleUserInput();
+ std::optional<SDL_Scancode> handleUserInput();
void renderPath(const demo::Positions& path);
int scaleFactor_;
diff --git a/demo/src/pacman_wrapper.cpp b/demo/src/pacman_wrapper.cpp
index 3428afc..665d847 100644
--- a/demo/src/pacman_wrapper.cpp
+++ b/demo/src/pacman_wrapper.cpp
@@ -54,7 +54,9 @@ PacmanWrapper::PacmanWrapper()
SDL_SetRenderDrawBlendMode(renderer_.get(), SDL_BLENDMODE_BLEND);
}
-void PacmanWrapper::handleUserInput() {
+std::optional<SDL_Scancode> PacmanWrapper::handleUserInput() {
+ std::optional<SDL_Scancode> commandOverride;
+
SDL_Event event;
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
@@ -75,15 +77,26 @@ void PacmanWrapper::handleUserInput() {
renderPath_ = !renderPath_;
break;
}
+ if (event.key.keysym.scancode == SDL_SCANCODE_UP || event.key.keysym.scancode == SDL_SCANCODE_DOWN ||
+ event.key.keysym.scancode == SDL_SCANCODE_LEFT || event.key.keysym.scancode == SDL_SCANCODE_RIGHT) {
+ commandOverride = event.key.keysym.scancode;
+ break;
+ }
}
}
+
+ return commandOverride;
}
void PacmanWrapper::progressGame(const demo::Command& command,
const demo::EnvironmentModel::ConstPtr& environmentModel) {
- handleUserInput();
+ std::optional<SDL_Scancode> commandOverride = handleUserInput();
- game_.input(command.scancode());
+ if (commandOverride) {
+ game_.input(commandOverride.value());
+ } else {
+ game_.input(command.scancode());
+ }
if (pause_) {
return; |
The exception is thrown by an out of bounds access to the Maze ( Stacktrace:
Looks like @ll-nick is this intentionally? auto nextPosition = environmentModel_->positionConsideringTunnel(pacmanPosition + move.deltaPosition);
→ if (environmentModel_->isWall(nextPosition)) {
continue;
} |
Nice investigative work 🕵️ Present-me thinks that the implementation of past-me makes absolutely no sense. You're right, the wrapped position should be returned no matter the type. The question is: Why is the wrapped position a wall? Did that make sense in the situation you described? And one other question: Should we implement the manual override into the demo? Might be handy in other situations too. 😀 |
That's a good question! And yes, it makes sense:
|
Ah yes, that makes sense. Thanks for the fix, I'll take a look now 👌 |
I just saw the demo crash when Pac-Man tried entering the tunnel during the
ChaseGhost
behavior. It would probably not have crashed with #21 but that's something we should investigate nevertheless.The text was updated successfully, but these errors were encountered: