the debugger says segfault is omitting exactly from ts3client_sendFile function. the strings for file location are definitely clean since if file not found it says file “not found” before segfault (so basically this means it occurs even before sending file to server)
anyID* res = new anyID;
ts3client_sendFile(
this->svHandlerID,
0,
"",
"spar.png",
0,
0,
"/home/max/Documents/",
res,
NULL
);
ts3client_freeMemory(res);
The Channel ID in this case is 0, the default channel ID should always be 1.
Do you get any error message?
I’ve attached an example below, maybe this helps you to solve the issue, If not feel free to reach out again and I will get that a dev involved with this issue.
serverConnectionHandlerID:
– The ID for the TeamSpeak server you’re connected to.
channelID:
– The ID of the channel you want to upload the file to.
channelPW:
– The password for that channel. Use an empty string ("") if there’s no password.
file:
– The name of the file (not path!) you want to upload. Example: "file.txt"
overwrite (int):
– * 1: Overwrite if the file exists on the server.
– * 0: Fail the transfer if the file already exists.
resume (int):
– * 1: Resume a previously interrupted transfer (appends to server file).
– * 0: Start a new upload.
sourceDirectory:
– The full, absolute path to the folder that contains the file. Example: "/home/user/documents"
result:
– Pointer to a variable where the transfer ID will be stored on success.
returnCode:
– A string used for tracking the request in async callbacks. Optional; use "" if not needed.
I haven’t tested it, but I assume the following. ts3client_sendFile is not a blocking call, instead you get a return code (which you disregard) and the SDK will run a callback with this returnCode to signal the upload is complete. I assume by calling ts3client_freeMemory immediately on the result pointer it crashes as it tries to free memory that hasn’t even been allocated yet. To test this you could just not free at all (creating a memory leak).
but this is only showing me in debug step-by-step mode (or whatever you call it), when it runs on without it, terminal shows me only first message from above. also the returning value is ERROR_ok.
Okay now I have a proper answer and solution for you:
Using ts3client_freeMemory in this case is incorrect, as this is only required for instances where the client lib itself allocates memory for returned values like “char " strings or arrays. In your code the caller is allocating the memory with "anyID res = new anyID” so you need to deallocate it himself again with “delete res”.
Using “new” is doing the allocation with C++ operators and the clientlib is using C free() in its ts3client_freeMemory() implementation, which results in undefined behaviour. You don’t even need to do any dynamic memory allocation for this kind of anyID value, which is just an primitive type of uint16_t.
You can do this instead:
anyID res = 0;
ts3client_sendFile(
this->svHandlerID,
channelID,
"",
"spar.png",
0,
0,
"/home/max/Documents/",
&res,
NULL
);
// No need for deallocating res
nothing changed. i’ve implemented simple project just to check this bug, and here’s how it looks in connection handler (just copypasted from my project with that function and your your code too):
static void hook_connection_status(uint64 serverConnectionHandlerID, int newStatus, uint errorNumber)
{
printf("Changed connection status to %d on connection %lu with error 0x%04X\n", newStatus, serverConnectionHandlerID, errorNumber);
if (newStatus == STATUS_CONNECTION_ESTABLISHED)
{
uint error = 0;
anyID res = 0;
error = ts3client_sendFile(
client_scHandlerID,
0,
"",
"spar.png",
0,
0,
"/home/max/Documents/",
&res,
NULL
);
}
}
(just replaced this->svHandlerID with client_scHandlerID)
so it still executes sendFile func and segfaulting next step further in program. terminal messages are same as I’ve described before.
p.s. it still the same without using error variable
We’ve just confirmed that we we’re able to upload a file with the 3.3.1 SDK.
Do you have all the required callbacks in your project?
funcs.onFileListEvent = onFileListEvent;
funcs.onFileListFinishedEvent = onFileListFinishedEvent;
funcs.onFileTransferStatusEvent = onFileTransferStatusEvent; // crash when not defined!!!
funcs.onFileInfoEvent = onFileInfoEvent;
Code snippet from the client_minimal_filetransfer example
If that still does not work, please provide me with a larger code snippet or your whole project. (Either here or via DM if you prefer)
Also interesting to know which SDK server you are using, as the server SDK has an extra call to enable File Transfer ts3server_enableFileManager as seen in the example for server_filetransfer.
When using the server_minimal it would not support File Transfer natively.