c++file-storagelibtorrentlibtorrent-rasterbar

libtorrent file_storage invalid : bad allocation


I am following libtorrent-maketorrent-example

I am runnin the client with following parameter

.\client.exe "base_text.txt" -o base_text.torrent -l

file_storage is declared as below with default constructor

    lt::file_storage fs;

The program is throwing exception at when it tries to add file

lt::add_files(fs, full_path, file_filter, flags);

I am guessing the issue could be because file_storage is invalid as the below statment which I added before calling lt::add_files is returns false i.e 0

std::cout << "Is file storage valid : " << fs.is_valid()<< std::endl;

I am getting bad allocation exception for lt::add_files

Args[1]= base_text.txt
Is file storage valid : 0
ERROR: bad allocation

and full path is C:\workspace\Project1%20POC\client\base_text.torrent

How do I solve this? Am I doing something wrong?


Solution

  • Issue was file path contained % project folder name was Project1%20POC I renamed it to Project1-POC and also made sure that full path is less than 260 characters which is the default threshold in Windows.

    Now lt::add_files not throwing bad allocation exception and the next line lt::create_torrent creates the torrent.