The following changes have been made to sba-1.6. If upgrading to a new
version, repeating these changes may be required.

--------------------------------------------------------------------------------

In sba_levmar.c, within the function sba_motstr_levmar_x, fixed the calculation
of number of variables to consider fixed camera and feature states.


Index: sba_levmar.c
===================================================================
--- sba_levmar.c	(revision 7055)
+++ sba_levmar.c	(working copy)
@@ -602,7 +602,7 @@
        eps3_sq=opts[3]*opts[3], eps4_sq=opts[4]*opts[4];
 double init_p_eL2;
 int nu=2, nu2, stop=0, nfev, njev=0, nlss=0;
-int nobs, nvars;
+int nobs, nvars, nconstvars;
 const int mmcon=m-mcon;
 PLS linsolver=NULL;
 int (*matinv)(double *A, int m)=NULL;
@@ -631,7 +631,8 @@
 
   nobs=nvis*mnp;
   nvars=m*cnp + n*pnp;
-  if(nobs<nvars){
+  nconstvars = mcon*cnp + ncon*pnp;
+  if(nobs<nvars-nconstvars){
     fprintf(stderr, "SBA: sba_motstr_levmar_x() cannot solve a problem with fewer measurements [%d] than unknowns [%d]\n", nobs, nvars);
     return SBA_ERROR;
   }


--------------------------------------------------------------------------------


In sba_levmar_wraps.c, make the callback function variables fjac non-static

Index: sba_levmar_wrap.c
===================================================================
--- sba_levmar_wrap.c	(revision 7078)
+++ sba_levmar_wrap.c	(working copy)
@@ -669,7 +669,7 @@
 {
 int retval;
 struct wrap_motstr_data_ wdata;
-static void (*fjac)(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *jac, void *adata);
+void (*fjac)(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *jac, void *adata);
 
   wdata.proj=proj;
   wdata.projac=projac;
@@ -868,7 +868,7 @@
 {
 int retval;
 struct wrap_str_data_ wdata;
-static void (*fjac)(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *jac, void *adata);
+void (*fjac)(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *jac, void *adata);
 
   wdata.proj=proj;
   wdata.projac=projac;


--------------------------------------------------------------------------------

In sba_lapack.c, prevented the retention of buffers in all called functions to
make sba safe for multi-threaded programs. Makesure a call to free the buffer
occurs before any return statement. By default, the functions sba_Axb_Chol and 
sba_symat_invert_BK are called.

Index: sba_lapack.c
===================================================================
--- sba_lapack.c	(revision 7055)
+++ sba_lapack.c	(working copy)
@@ -372,8 +372,8 @@
  */
 int sba_Axb_Chol(double *A, double *B, double *x, int m, int iscolmaj)
 {
-static double *buf=NULL;
-static int buf_sz=0;
+double *buf=NULL;
+int buf_sz=0;
 
 double *a;
 int a_sz, tot_sz;
@@ -432,7 +432,9 @@
       exit(1);
     }
     else{
-      fprintf(stderr, "LAPACK error: the leading minor of order %d is not positive definite,\nthe factorization could not be completed for dpotf2/dpotrf in sba_Axb_Chol()\n", info);
+      /* Disabled, since it is printed a lot */
+      /*fprintf(stderr, "LAPACK error: the leading minor of order %d is not positive definite,\nthe factorization could not be completed for dpotf2/dpotrf in sba_Axb_Chol()\n", info);*/
+      free(buf);
       return 0;
     }
   }
@@ -456,6 +458,7 @@
     }
     else{
       fprintf(stderr, "LAPACK error: the %d-th diagonal element of A is zero (singular matrix) in sba_Axb_Chol()\n", info);
+      free(buf);
       return 0;
     }
   }
@@ -470,11 +473,13 @@
     }
     else{
       fprintf(stderr, "LAPACK error: the %d-th diagonal element of A is zero (singular matrix) in sba_Axb_Chol()\n", info);
+      free(buf);
       return 0;
     }
   }
 #endif /* 1 */
 
+        free(buf);
 	return 1;
 }
 
@@ -1036,8 +1041,8 @@
  */
 int sba_symat_invert_BK(double *A, int m)
 {
-static double *buf=NULL;
-static int buf_sz=0, nb=0;
+double *buf=NULL;
+int buf_sz=0, nb=0;
 
 int a_sz, ipiv_sz, work_sz, tot_sz;
 register int i, j;
@@ -1098,6 +1103,7 @@
 		}
 		else{
 			fprintf(stderr, "singular block diagonal matrix D for dsytrf in sba_symat_invert_BK() [D(%d, %d) is zero]\n", info, info);
+			free(buf);
 			return 0;
 		}
 	}
@@ -1111,6 +1117,7 @@
 		}
 		else{
 			fprintf(stderr, "D(%d, %d)=0, matrix is singular and its inverse could not be computed in sba_symat_invert_BK()\n", info, info);
+			free(buf);
 			return 0;
 		}
 	}
@@ -1120,6 +1127,7 @@
 		for(j=0; j<=i; ++j)
       A[i*m+j]=a[i+j*m];
 
+	free(buf);
 	return 1;
 }
 
