From 17d79e8d8e585a39ca8b16efa1d18a11409f8079 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 3 Mar 2013 15:38:52 -0500 Subject: [PATCH] fix crash when drawing particles in invalid coordinates (using console) --- src/graphics/Renderer.cpp | 4 ++-- src/preview/PreviewController.cpp | 7 ------- src/preview/PreviewModel.cpp | 8 -------- src/preview/PreviewView.cpp | 11 +++-------- src/simulation/Simulation.cpp | 14 +++++++------- 5 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 486a0d42b..3a1a2cd4b 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -1172,10 +1172,10 @@ void Renderer::render_parts() fnx = sim->parts[i].x; fny = sim->parts[i].y; - if((sim->photons[ny][nx]&0xFF) && !(sim->elements[t].Properties & TYPE_ENERGY) && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH) - continue; if(nx >= XRES || nx < 0 || ny >= YRES || ny < 0) continue; + if((sim->photons[ny][nx]&0xFF) && !(sim->elements[t].Properties & TYPE_ENERGY) && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH) + continue; //Defaults pixel_mode = 0 | PMODE_FLAT; diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp index 37561b7b5..1616c6399 100644 --- a/src/preview/PreviewController.cpp +++ b/src/preview/PreviewController.cpp @@ -1,10 +1,3 @@ -/* - * PreviewController.cpp - * - * Created on: Jan 21, 2012 - * Author: Simon - */ - #include #include "client/Client.h" #include "PreviewController.h" diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp index b5dbf40d2..ea3904d79 100644 --- a/src/preview/PreviewModel.cpp +++ b/src/preview/PreviewModel.cpp @@ -1,10 +1,3 @@ -/* - * PreviewModel.cpp - * - * Created on: Jan 21, 2012 - * Author: Simon - */ - #include #include "PreviewModel.h" #include "client/Client.h" @@ -25,7 +18,6 @@ PreviewModel::PreviewModel(): commentsPageNumber(1), commentBoxEnabled(false) { - // TODO Auto-generated constructor stub } diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 61a0c8f46..1859a2a7d 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -1,10 +1,3 @@ -/* - * PreviewView.cpp - * - * Created on: Jan 21, 2012 - * Author: Simon - */ - #include #include #include @@ -274,7 +267,7 @@ void PreviewView::OnDraw() g->drawrect(Position.X, Position.Y, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 100); g->draw_line(Position.X+XRES/2, Position.Y+1, Position.X+XRES/2, Position.Y+Size.Y-2, 200, 200, 200, 255); - if(!(!votesUp && !votesDown)) + if(votesUp || votesDown) { float ryf; int nyu, nyd; @@ -573,5 +566,7 @@ PreviewView::~PreviewView() RemoveComponent(submitCommentButton); delete submitCommentButton; } + if(savePreview) + delete savePreview; } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index d64ccf7b2..ef3c3d9fb 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2947,10 +2947,10 @@ int Simulation::create_part(int p, int x, int y, int tv) parts[i].life = 75; break; /*Testing - case PT_WOOD: - parts[i].life = 150; - break; - End Testing*/ + case PT_WOOD: + parts[i].life = 150; + break; + End Testing*/ case PT_WARP: parts[i].life = rand()%95+70; break; @@ -3555,7 +3555,7 @@ void Simulation::update_particles_i(int start, int inc) { golnum = parts[r>>8].ctype+1; if (golnum<=0 || golnum>NGOLALT) { - parts[r>>8].type = PT_NONE; + kill_part(r>>8); continue; } if (parts[r>>8].tmp == grule[golnum][9]-1) { @@ -3575,7 +3575,7 @@ void Simulation::update_particles_i(int start, int inc) } else { parts[r>>8].tmp --; if (parts[r>>8].tmp<=0) - parts[r>>8].type = PT_NONE;//using kill_part makes it not work + kill_part(r>>8); } } //} @@ -3604,7 +3604,7 @@ void Simulation::update_particles_i(int start, int inc) parts[r>>8].tmp --; } if (r && parts[r>>8].tmp<=0) - parts[r>>8].type = PT_NONE;//using kill_part makes it not work + kill_part(r>>8); } for ( z = 0; z<=NGOL; z++) gol2[ny][nx][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this.