From 083eef7a50a223bd5993ca4715e6ada42bbca3a0 Mon Sep 17 00:00:00 2001 From: Elisey Puzko Date: Thu, 22 Feb 2018 22:27:43 +0300 Subject: Quick fix. A quick fix for a segfault caused by the block placement when there aren't any selected blocks. --- src/GameState.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/GameState.cpp b/src/GameState.cpp index b963ef0..743a750 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -7,11 +7,11 @@ #include "Packet.hpp" void GameState::Update(float deltaTime) { - if (g_IsGameStarted) { - std::chrono::steady_clock clock; - static auto timeOfPreviousSendedPacket(clock.now()); + if (g_IsGameStarted) { + std::chrono::steady_clock clock; + static auto timeOfPreviousSendedPacket(clock.now()); auto delta = clock.now() - timeOfPreviousSendedPacket; - using namespace std::chrono_literals; + using namespace std::chrono_literals; if (delta >= 50ms) { auto packetToSend = std::make_shared( player->pos.x, player->pos.y, player->pos.z, @@ -58,7 +58,7 @@ void GameState::Update(float deltaTime) { isBlockSelected = raycast.isHit; raycastHit = raycast.hitPos; - } + } } void GameState::UpdatePacket(std::shared_ptr ptr) { @@ -559,6 +559,9 @@ glm::mat4 GameState::GetViewMatrix() { // send_packet(packet_type=start_digging_packet) // delay(time=selected_block_dig_time, action=finish_digging) void GameState::StartDigging() { + if (!isBlockSelected) + return; + auto packetStart = std::make_shared(0,selectedBlock,1); auto packet = std::static_pointer_cast(packetStart); PUSH_EVENT("SendPacket",packet); @@ -584,6 +587,9 @@ void GameState::CancelDigging() { } void GameState::PlaceBlock() { + if (!isBlockSelected) + return; + auto packetPlace = std::make_shared( selectedBlock, 1, 0, 0.0, 0.0, 0.0); -- cgit v1.2.3