#ifdef DEBUG_REGION
msg_Err( p_spu, "Merging %d and %d", i_best_i, i_best_j );
#endif
- r_add( ®ion[i_best_i], ®ion[i_best_j] );
+ if( i_best_j >= 0 && i_best_i >= 0 )
+ {
+ r_add( ®ion[i_best_i], ®ion[i_best_j] );
- if( i_best_j+1 < i_region )
- memmove( ®ion[i_best_j], ®ion[i_best_j+1], sizeof(*region) * ( i_region - (i_best_j+1) ) );
- i_region--;
+ if( i_best_j+1 < i_region )
+ memmove( ®ion[i_best_j], ®ion[i_best_j+1], sizeof(*region) * ( i_region - (i_best_j+1) ) );
+ i_region--;
+ }
}
}