Error in osqpSolve(private$.work) : external pointer is not valid

I am trying to solve a quadratic program by R-OSQP, I got this error

    Error in osqpSolve(private$.work) : external pointer is not valid

what is that for? the size of P is 1803*1803 and A is 2 times bigger

Code:

library(osqp)
P<- matrix(0,18603,18603)
diag(P[1:21,1:21])<-1
df1<-train[,]
ModeTrain<-df1$MODE
df<-df1[,]
df<-df[,-1]
A<-scale(df)
m2<-data.matrix(A)
dim(m2)
h<-matrix(1, 6194,1)
m2<-cbind(m2,h)
BigKernel<-Matrix::bdiag(replicate(3, m2, simplify = FALSE))
BigKernel<-as.matrix(BigKernel)
Amat<-BigKernel[,]
vec_mode<-ModeTrain
vec_mode<-as.numeric(factor(vec_mode))
library(reshape2)
matr <- matrix(-1, nrow = length(vec_mode), ncol = max(vec_mode))
matr[cbind(seq_along(vec_mode), vec_mode)]<- 1
colnames(matr) <- paste0( seq_len(max(vec_mode)))
Y.long<-melt(matr, id.vars = 1:3)
y<-Y.long[,-1:-2]
Am<-Amat[,]y
I<- matrix(0,18582 ,18582 )
diag(I) <- 1
A<-cbind(Am,I)
Z<- matrix(0,18582 ,21)
Ep<- matrix(0,18582 ,18582 )
diag(Ep) <- 1
A1<-cbind(Z,Ep)
AA<-rbind(A,A1)
w<-matrix(0,21,1)
a<-matrix(10,18582,1)
q<- c(w,a)
u<-rep(c(10), times = 2
18582)
l1<-rep(c(1), times = 18582 )
l2<-rep(c(0), times = 18582 )
l<-c(l1,l2)
settings <- osqpSettings(verbose = TRUE)
res <- solve_osqp(P, q, AA, l, u, settings)
res$x

Which OS and which version of OSQP are you using? Note that we very recently released v0.6.0 on CRAN and github, which may have solved (or caused!) your problem.