Problem with printing unique permuation with recursion

A simple code to print all unique permutation. Somehow it is not working for a

allPermutation_unique("abca", 0, 4);

it is avoiding some repeted permutation but not all. the output for above is

abca
abac
acba
acab
aacb
aabc
baca
baac
bcaa
cbaa
caba
caab
caab
caba

The code is as follow:

    void allPermutation_unique(string str, int l, int r)
    {
        if(l==r){
            cout<<str<<"\n";
            return;
        }
    
    for(int i=l;i<r;i++)
    {
        if(str[i] == str[l] && i!=l)
            continue;

        swap(str[l], str[i]);
        allPermutation_unique(str, l+1, r);
        swap(str[l], str[i]);
    }

}

Can someone help me to find what i am doing wrong?