From a7667081474c62cc9b214756f8c760f328abccdd Mon Sep 17 00:00:00 2001 From: NaiJi Date: Sat, 9 Jan 2021 00:53:24 +0300 Subject: [PATCH] Fix runtime crash --- CMakeLists.txt | 32 ++++++++++++-------------------- board.cpp | 2 +- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c27cf2a..d2d3e4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,28 +7,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(SOURCES application.cpp board.cpp main.cpp) set(HEADER_FILES application.h board.h filepath_util.h output_util.h) -set(SFML_STATIC_LIBRARIES TRUE) #set to FALSE if you have sfml installed from package manager and you don't want to link it statically - # STATIC # # You need to build SFML from sources with cmake -if (SFML_STATIC_LIBRARIES) - set(SFML_LIB_DIR - ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-graphics.so.2.5 - ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-system.so.2.5 - ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-window.so.2.5) - set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include) - - include_directories(${SFML_INCL_DIR}) - - add_executable(sliding-puzzle ${SOURCES} ${HEADER_FILES} ) - target_link_libraries(sliding-puzzle ${SFML_LIB_DIR}) -endif() +set(SFML_LIB_DIR + ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-graphics.so.2.5 + ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-system.so.2.5 + ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-window.so.2.5) +set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include) +include_directories(${SFML_INCL_DIR}) +add_executable(sliding-puzzle ${SOURCES} ${HEADER_FILES} ) +target_link_libraries(sliding-puzzle ${SFML_LIB_DIR}) # DYNAMIC # # You only need to install SFML from your package manager -if (NOT SFML_STATIC_LIBRARIES) - find_package(SFML REQUIRED graphics window system) - include_directories(${SFML_INCLUDE_DIR}) - add_executable(sliding-puzzle ${SOURCES} ${HEADER_FILES} ) - target_link_libraries(sliding-puzzle ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}) -endif() +#find_package(SFML REQUIRED graphics window system) +#include_directories(${SFML_INCLUDE_DIR}) +#target_link_libraries(sliding-puzzle ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}) +#add_executable(sliding-puzzle ${SOURCES} ${HEADER_FILES} ) diff --git a/board.cpp b/board.cpp index 6d6e2b6..9119394 100644 --- a/board.cpp +++ b/board.cpp @@ -144,7 +144,7 @@ bool Board::moveSelection(const DIRECTION &direction) break; case DIRECTION::DOWN: - if (selection_index > (cells_on_width * (cells_on_height - 1))) // if bottom row + if (selection_index >= (cells_on_width * (cells_on_height - 1))) // if bottom row return false; selection_index += cells_on_width; setSelectionVertex(selection_index);