Hello,
Unreal engine crash when i’m manipulating a string. I don’t have any compilation error and this code works outside of unreal engine(I did ALOT of test). If it’s possible, I don’t want to use FString(I don’t like it).I’m using the 4.8.3 version of unreal. Here some code where my engine crash.
void TwitClient::generateNonceTimestamp()
{
char szTime[32];
char szRand[32];
static char Alphabet[63] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
memset(szTime, 0, 32);
memset(szRand, 0, 32);
sprintf_s(szRand, "%x", Alphabet[rand() % 63]);
sprintf_s(szTime, "%ld", time(NULL));
oauth_nonce.assign(szTime); // CRASH HERE
oauth_nonce.append(szRand);
while (oauth_nonce.size() < 32)
{
sprintf_s(szRand, "%x", Alphabet[rand() % 63]);
oauth_nonce += szRand;
}
if (oauth_nonce.size() > 32)
oauth_nonce.erase(32, std::string::npos);
oauth_timeStamp = szTime;
}
And my class:
#pragma once
#include <map>
#include <string>
#include "Http.h"
/**
*
*/
class TWITHUNTER_API TwitClient : public UObject
{
public:
TwitClient();
~TwitClient();
bool initialize();
void oauthRequestToken();
void oauthAccessToken(std::string const&, std::string const&, bool const);
void oauthAuthorize();
void getHomeTimeline();
void retweetToId(std::string const&);
void favoriteId(std::string const&);
void logOut();
bool getHeader(std::string const&, std::map<std::string, std::string>, std::string const&, std::string&);
void generateNonceTimestamp();
void createSignature(std::map<std::string, std::string>, std::string const&, std::string const&, std::string&);
void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
std::string const& getMessageBody() const { return _messagebody; }
std::string char2hex(char dec);
std::string urlencode(const std::string &c);
private:
std::string oauth_consumer_key;
std::string oauth_consumer_secret;
std::string oauth_nonce;
std::string oauth_timeStamp;
std::string oauth_signature_method;
std::string oauth_version;
std::string oauth_tokenKey;
std::string oauth_tokenSecret;
std::string oauth_pin;
std::string oauth_callback;
std::string _password;
std::string _username;
FHttpModule *Http;
std::string _messagebody;
};
Thanks in advance.