From cf464f1ed83479be717301800e87362eae524144 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 18 Aug 2015 09:55:18 +1000 Subject: [PATCH] Fixed various crashes when enabling AI debug (e.g. missing textures, heap corruption because the hpp file did not know about AI_DEBUG and so did not declare some variables). --- src/graphics/show_curve.cpp | 4 ++++ src/graphics/stk_mesh.cpp | 5 ++++- src/karts/controller/skidding_ai.cpp | 22 +++++----------------- src/karts/controller/skidding_ai.hpp | 21 +++++++++++++++++++++ 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/graphics/show_curve.cpp b/src/graphics/show_curve.cpp index 0d1860528..9d1227e7c 100644 --- a/src/graphics/show_curve.cpp +++ b/src/graphics/show_curve.cpp @@ -18,6 +18,7 @@ #include "graphics/show_curve.hpp" +#include "graphics/glwrap.hpp" #include "graphics/irr_driver.hpp" #include "utils/vec3.hpp" @@ -64,6 +65,9 @@ void ShowCurve::addEmptyMesh() m_mesh = irr_driver->createQuadMesh(&m, /*create_one_quad*/ false); m_buffer = m_mesh->getMeshBuffer(0); + m_buffer->getMaterial().setTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180))); + m_buffer->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); + assert(m_buffer->getVertexType()==video::EVT_STANDARD); } // addEmptyMesh diff --git a/src/graphics/stk_mesh.cpp b/src/graphics/stk_mesh.cpp index 1c1532e25..0589a0df1 100644 --- a/src/graphics/stk_mesh.cpp +++ b/src/graphics/stk_mesh.cpp @@ -252,13 +252,16 @@ void fillLocalBuffer(GLMesh &mesh, scene::IMeshBuffer* mb) glGenBuffers(1, &(mesh.index_buffer)); glBindBuffer(GL_ARRAY_BUFFER, mesh.vertex_buffer); + const void* vertices = mb->getVertices(); const u32 vertexCount = mb->getVertexCount(); + // This can happen for certain debug structures, e.g. ShowCurve + if (vertexCount == 0) + return; const c8* vbuf = static_cast(vertices); glBufferData(GL_ARRAY_BUFFER, vertexCount * mesh.Stride, vbuf, GL_STREAM_DRAW); - assert(vertexCount); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.index_buffer); const void* indices = mb->getIndices(); diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 74f40a84d..740197ecd 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -19,24 +19,10 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -//The AI debugging works best with just 1 AI kart, so set the number of karts -//to 2 in main.cpp with quickstart and run supertuxkart with the arg -N. -#ifdef DEBUG - // Enable AI graphical debugging -# undef AI_DEBUG - // Shows left and right lines when using new findNonCrashing function -# undef AI_DEBUG_NEW_FIND_NON_CRASHING - // Show the predicted turn circles -# undef AI_DEBUG_CIRCLES - // Show the heading of the kart -# undef AI_DEBUG_KART_HEADING - // Shows line from kart to its aim point -# undef AI_DEBUG_KART_AIM -#endif - #include "karts/controller/skidding_ai.hpp" #ifdef AI_DEBUG +# include "graphics/glwrap.hpp" # include "graphics/irr_driver.hpp" #endif #include "graphics/show_curve.hpp" @@ -110,6 +96,8 @@ SkiddingAI::SkiddingAI(AbstractKart *kart) i==2 ? 128 : 0); m_debug_sphere[i] = irr_driver->addSphere(1.0f, col_debug); m_debug_sphere[i]->setVisible(false); + m_debug_sphere[i]->setMaterialTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180))); + m_debug_sphere[i]->setMaterialTexture(1, getUnicolorTexture(video::SColor(128, 255, 105, 180))); } m_debug_sphere[m_point_selection_algorithm]->setVisible(true); m_item_sphere = irr_driver->addSphere(1.0f); @@ -166,7 +154,7 @@ SkiddingAI::~SkiddingAI() { delete m_curve[i]; } - delete m_curve; + delete [] m_curve; #endif } // ~SkiddingAI @@ -1843,7 +1831,7 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node) m_curve[CURVE_RIGHT]->addPoint(q[RIGHT_END_POINT]+eps1); m_curve[CURVE_RIGHT]->addPoint(m_kart->getXYZ()+eps1); #endif -#ifdef AI_DEBUG_KART_HEADING +#if defined(AI_DEBUG_KART_HEADING) || defined(AI_DEBUG_NEW_FIND_NON_CRASHING) const Vec3 eps(0,0.5f,0); m_curve[CURVE_KART]->clear(); m_curve[CURVE_KART]->addPoint(m_kart->getXYZ()+eps); diff --git a/src/karts/controller/skidding_ai.hpp b/src/karts/controller/skidding_ai.hpp index 7f3d90ef8..55b8749f6 100644 --- a/src/karts/controller/skidding_ai.hpp +++ b/src/karts/controller/skidding_ai.hpp @@ -22,6 +22,27 @@ #ifndef HEADER_SKIDDING_AI_HPP #define HEADER_SKIDDING_AI_HPP +// Some debugging features for the AI. For example you can visualise the +// point the AI is aiming at, or visualise the curve the AI is predicting. +// It works best with just 1 AI kart, so set the number of karts +// to 2 in main.cpp with quickstart and run supertuxkart with the arg -N. +// Or use --profile-laps=99 and run just one AI. Using the debug camera +// (top view) is useful, too + +#ifdef DEBUG + // Enable AI graphical debugging +# define AI_DEBUG + // Shows left and right lines when using new findNonCrashing function +# undef AI_DEBUG_NEW_FIND_NON_CRASHING + // Show the predicted turn circles +# undef AI_DEBUG_CIRCLES + // Show the heading of the kart +# undef AI_DEBUG_KART_HEADING + // Shows line from kart to its aim point +# undef AI_DEBUG_KART_AIM +#endif + + #include "karts/controller/ai_base_controller.hpp" #include "race/race_manager.hpp" #include "tracks/graph_node.hpp"