Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on OnHTTPResponse #164

Closed
PixellUp opened this issue Aug 9, 2016 · 12 comments
Closed

Crash on OnHTTPResponse #164

PixellUp opened this issue Aug 9, 2016 · 12 comments

Comments

@PixellUp
Copy link

PixellUp commented Aug 9, 2016

Just like the title said when OnHTTPResponse is called it crash the server with the following code. Hello world code was used -> http://pastebin.com/WHc79d4y

SA-MP Server: 0.3.7-R2

Exception At Address: 0x0F094ABC Module: (helloworld.DLL)

Registers:

EAX: 0x00000001 EBX: 0x0019E904 ECX: 0x8C942EDF EDX: 0x00000004

ESI: 0x0F064075 EDI: 0x0F09760C EBP: 0x0019F730 ESP: 0x0019E8E8

EFLAGS: 0x00000246

Stack:

+0000: 0x00000000 0x00000000 0x00000009 0x0019F754

+0010: 0x0000001E 0x00000000 0x00000002 0x00740053

+0020: 0x00630061 0x0020006B 0x00720061 0x0075006F

+0030: 0x0064006E 0x00740020 0x00650068 0x00760020

+0040: 0x00720061 0x00610069 0x006C0062 0x00200065

+0050: 0x00730027 0x006F0068 0x00640077 0x00740061

+0060: 0x00270061 0x00770020 0x00730061 0x00630020

+0070: 0x0072006F 0x00750072 0x00740070 0x00640065

+0080: 0x0000002E 0x004A5A3B 0x17214023 0x0019E9CC

+0090: 0x004A05EB 0x000001A8 0x005164C0 0x0000006C

+00A0: 0x00000003 0x0019E9CC 0x004A5A71 0x00AF06B8

+00B0: 0x004A06B9 0x00000003 0x004A06D6 0x00000000

+00C0: 0x004E59F8 0x00000003 0x0000FE87 0x0019E9A4

+00D0: 0x00000003 0x0019ECA8 0x0049D208 0x004BA858

+00E0: 0xFFFFFFFF 0x004A06D6 0x0049EBCD 0x00000003

+00F0: 0x00000000 0x00000001 0x0019E8B8 0x00000001

+0100: 0x0019ECE4 0x0019F02C 0x004AA54B 0xFFFFFFFF

+0110: 0x0100007F 0x0045A4E3 0x004B9D28 0x0019EB21

+0120: 0x00000200 0x00000001 0x00000008 0x00000003

+0130: 0x0100007F 0x0045EA99 0x00000200

0x00000000

@PixellUp
Copy link
Author

Does anyone have any solution for this problem ? @Zeex @ikkentim

@Zeex
Copy link
Owner

Zeex commented Aug 15, 2016

It might be because you defined OnHTTPRespone using the wrong calling convention. Try replacing this:

void SAMPGDK_CALL OnHTTPResponse(int index, int response_code, char data[])

with:

PLUGIN_EXPORT void PLUGIN_CALL OnHTTPResponse(int index, int response_code, char data[])

@PixellUp
Copy link
Author

If I try to replace it, it shows me this error.
Error 'OnHTTPResponse': second C linkage of overloaded function not allowed D:\..\helloworld.cpp
I want to point out that MyHttpResponse callback isn't been called at all, even when is defined in helloworld.def

@Zeex
Copy link
Owner

Zeex commented Aug 20, 2016

The definition of your OnHTTPResponse doesn't match the declaration in a_http.h, that's why the compiler is complaining.

You need to add const to the last parameter, else it thinks it's an overloaded function. Apparently if a function is overloaded it can't be exported as extern "C" function (hence the "C linkage" part).

@Zeex
Copy link
Owner

Zeex commented Aug 20, 2016

Since you're in C++ you could also use one of numerous HTTP libraries instead. Libcurl is a popular one, but there seems to be a lot more of them:

https://curl.haxx.se/libcurl/competitors.html

Same goes for MySQL and other stuff that's used outside of SA-MP - there are libraries for that too.

@Zeex
Copy link
Owner

Zeex commented Aug 20, 2016

This seems like a useful list: https://github.com/fffaraz/awesome-cpp

@PixellUp
Copy link
Author

Could you point me at what exactly is need to be made to OnHTTPResponse to be working? From what I understand he is been called whatever HTTP is made, but judging from PAWN my custom callback MyHttpResponse should be the one that is called, instead of OnHTTPResponse which isn't happening.

@PixellUp
Copy link
Author

My decision for PAWN-like syntax is for simplicity,familiarity and easy of use (cause I'm not so good with C+).

@Zeex
Copy link
Owner

Zeex commented Aug 29, 2016

You can't have a custom callback with HTTP() in GDK, the callback is always OnHTTPResponse(). The last parameter of HTTP is actually data, not a callback name.

Here's an example of HTTP usage: https://github.com/Zeex/sampgdk/blob/http-example/plugins/helloworld/helloworld.cpp

@PixellUp
Copy link
Author

PixellUp commented Aug 31, 2016

Even copying everything from HTTP example, nothing is been called.
Server log - http://pastebin.com/sPHM41EV

@Zeex
Copy link
Owner

Zeex commented Aug 31, 2016

Did you add OnHTTPResponse to your .def file?

https://github.com/Zeex/sampgdk/blob/http-example/plugins/helloworld/helloworld.def

@PixellUp
Copy link
Author

PixellUp commented Sep 1, 2016

Everything work now as it should be. Thank you much for those 23 days of help :)

@PixellUp PixellUp closed this as completed Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants