Skip to content

Commit 55899a3

Browse files
committed
Crash issue fix
- logprintf pointer was not referenced correctly
1 parent 73b10a4 commit 55899a3

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/ChatBotHelper.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ bool ChatBotHelper::DoRequest(std::string& response, const std::string request,
163163
{
164164
curl_easy_cleanup(curl);
165165
curl_slist_free_all(headers);
166-
logprintf("\n\nChat Bot Request Failed! Error: %s\n", exc.what());
166+
167+
logprintf("[ChatBot Plugin]: Request Parsing Failed! Error: %s", exc.what());
168+
167169
return false;
168170
}
169171
}
170172
else
171-
logprintf("\n\nChat Bot Request Failed! Error: %s\n", curl_easy_strerror(res));
173+
logprintf("[ChatBot Plugin]: Failed! Error: %s\n", curl_easy_strerror(res));
172174

173175
curl_easy_cleanup(curl);
174176
curl_slist_free_all(headers);
@@ -189,17 +191,9 @@ std::string ChatBotHelper::GetBotAnswer(const ChatBotParams& params, nlohmann::j
189191
{
190192
std::string answer;
191193

192-
try
193-
{
194-
nlohmann::json error = response.at("error");
195-
196-
if (!error.empty())
197-
return response.dump(4).c_str();
198-
}
199-
catch (...)
200-
{
201-
//errore non trovato
202-
}
194+
//controllo errori
195+
if (response.contains("error"))
196+
return response.dump(4).c_str();
203197

204198
switch (params.botType)
205199
{
@@ -218,8 +212,8 @@ std::string ChatBotHelper::GetBotAnswer(const ChatBotParams& params, nlohmann::j
218212
}
219213
catch (std::exception &exc)
220214
{
221-
logprintf("ChatBot Plugin Exception GetBotAnswer(): %s\n", exc.what());
222-
logprintf("Chatbot Plugin Exception Response:\n%s", response.dump(4).c_str());
215+
logprintf("[ChatBot Plugin]: Exception GetBotAnswer(): %s\n", exc.what());
216+
logprintf("[ChatBot Plugin]: Exception Response:\n%s", response.dump(4).c_str());
223217

224218
return response.dump(4).c_str();
225219
}

src/SampHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef void (*logprintf_t)(const char*, ...);
1818
return 0; \
1919
}
2020

21-
static logprintf_t logprintf;
21+
extern logprintf_t logprintf;
2222

2323
extern void* pAMXFunctions;
2424
static std::set<AMX*> interfaces;

src/main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ static std::mutex memoryLock;
2424
static std::thread requestsThread;
2525
static std::atomic<bool> running;
2626

27+
28+
logprintf_t logprintf;
29+
2730
static void DoRequest(std::string prompt, int id)
2831
{
2932
std::string answer;
@@ -109,9 +112,13 @@ PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
109112

110113
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
111114
{
115+
Sleep(5000);
116+
112117
pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
113118
logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];
114-
logprintf("\n\nChatBot API Plugin %s by SimoSbara loaded\n", PLUGIN_VERSION);
119+
logprintf("ChatBot Plugin %s by SimoSbara loaded", PLUGIN_VERSION);
120+
121+
//Sleep(5000);
115122

116123
InitParams();
117124

@@ -126,7 +133,7 @@ PLUGIN_EXPORT void PLUGIN_CALL Unload()
126133
{
127134
running = false;
128135

129-
logprintf("\n\nChatBot API Plugin %s by SimoSbara unloaded\n", PLUGIN_VERSION);
136+
logprintf("ChatBot Plugin %s by SimoSbara unloaded", PLUGIN_VERSION);
130137
}
131138

132139
static cell AMX_NATIVE_CALL n_SetChatBotEncoding(AMX* amx, cell* params)

0 commit comments

Comments
 (0)