fix six possible "divide by zero"

This commit is contained in:
Hubert Jarosz 2016-03-01 00:08:33 +01:00 committed by Hubert Jarosz
parent bf7f9244a9
commit 7b07bcaf44
No known key found for this signature in database
GPG key ID: 3078B3E2110D6947
6 changed files with 23 additions and 15 deletions

View file

@ -64,7 +64,11 @@ void Navigation::_navmesh_link(int p_id) {
continue;
}
p.center=center/plen;
p.center = center;
if( plen != 0 ) {
p.center /= plen;
}
//connect
@ -721,5 +725,3 @@ Navigation::Navigation() {
last_id=1;
up=Vector3(0,1,0);
}

View file

@ -361,7 +361,10 @@ void ColorPicker::_preset_input(const InputEvent &ev) {
emit_signal("color_changed", color);
} else if (ev.type == InputEvent::MOUSE_MOTION) {
const InputEventMouse &mev = ev.mouse_motion;
int index = mev.x/(preset->get_size().x/presets.size());
int index = mev.x * presets.size();
if( preset->get_size().x != 0 ) {
index /= preset->get_size().x;
}
if (index<0 || index >= presets.size())
return;
preset->set_tooltip("Color: #"+presets[index].to_html(presets[index].a<1)+"\n"
@ -684,4 +687,3 @@ ColorPickerButton::ColorPickerButton() {
picker->connect("color_changed",this,"_color_changed");
add_child(popup);
}

View file

@ -5667,7 +5667,10 @@ void VisualServerRaster::_instance_validate_autorooms(Instance *p_geometry) {
int pass = room->room_info->room->bounds.get_points_inside(dst_points,point_count);
float ratio = (float)pass / point_count;
float ratio = pass;
if( point_count != 0 ) {
ratio /= (float)point_count;
}
if (ratio>0.5) // should make some constant
p_geometry->valid_auto_rooms.insert(room);
@ -7670,5 +7673,3 @@ VisualServerRaster::VisualServerRaster(Rasterizer *p_rasterizer) {
VisualServerRaster::~VisualServerRaster()
{
}

View file

@ -725,7 +725,11 @@ Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) {
} else {
half=1;
ofs=h/2;
v = ((j-(h/2))/(float)(h/2)) * 2.0 - 1.0;
if( (float)(h/2) != 0 ) {
v = ((j-(h/2))/(float)(h/2)) * 2.0 - 1.0;
} else {
v = ((j-(h/2))/(float)(1/2)) * 2.0 - 1.0;
}
}
uint8_t* imgofs = &imgw[(j*w+i)*3];

View file

@ -1784,7 +1784,8 @@ void ScriptEditor::_update_script_colors() {
if (h>hist_size) {
continue;
}
float v = Math::ease((edit_pass-pass)/float(hist_size),0.4);
int non_zero_hist_size = ( hist_size == 0 ) ? 1 : hist_size;
float v = Math::ease((edit_pass-pass)/float(non_zero_hist_size),0.4);
script_list->set_item_custom_bg_color(i,hot_color.linear_interpolate(cold_color,v));
@ -2704,4 +2705,3 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) {
ScriptEditorPlugin::~ScriptEditorPlugin()
{
}

View file

@ -2084,7 +2084,9 @@ void SpatialEditorViewport::_menu_option(int p_option) {
count++;
}
center/=float(count);
if( count != 0 ) {
center/=float(count);
}
cursor.pos=center;
} break;
@ -4240,6 +4242,3 @@ SpatialEditorPlugin::SpatialEditorPlugin(EditorNode *p_node) {
SpatialEditorPlugin::~SpatialEditorPlugin() {
}