Ancurio / mkxp

Free Software implementation of the Ruby Game Scripting System (RGSS)
GNU General Public License v2.0
511 stars 129 forks source link

Unable to use Socket library #45

Closed khkramer closed 9 years ago

khkramer commented 9 years ago
Exception `SocketError' at (RMX-OS) Script:771 - getaddrinfo: Either the applica
tion has not called WSAStartup, or WSAStartup failed.

I've googled around for this error but nothing relevant came up. I've tried recompiling Ruby several times in the hopes that it would fix it but no luck so far. Here is the output of $LOADED_FEATURES:

["enumerator.so", "G:/Pokemon_NoxMK/lib/zlib.so", "G:/Pokemon_NoxMK/lib/socket.so", "G:/Pokemon_NoxMK/lib/socket.rb"]
cremno commented 9 years ago

Can you try adding ruby_sysinit(0, NULL) at the beginning of mriBindingExecute in binding-mri/binding-mri.cpp?

khkramer commented 9 years ago

Added it like this:

static void mriBindingExecute()
{
    ruby_sysinit(0, NULL);
    ruby_setup();
    rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));

    RbData rbData;
    shState->setBindingData(&rbData);

    mriBindingInit();

    std::string &customScript = shState->rtData().config.customScript;
    if (!customScript.empty())
        runCustomScript(customScript);
    else
        runRMXPScripts();

    VALUE exc = rb_errinfo();
    if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit))
        showExc(exc);

    ruby_cleanup(0);

    shState->rtData().rqTermAck = true;
}

and recompiled. It just exits without any error messages whatsoever.

Then I tried it like this:

static void mriBindingExecute()
{

    ruby_setup();
        ruby_sysinit(0, NULL);
    rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));

    RbData rbData;
    shState->setBindingData(&rbData);

    mriBindingInit();

    std::string &customScript = shState->rtData().config.customScript;
    if (!customScript.empty())
        runCustomScript(customScript);
    else
        runRMXPScripts();

    VALUE exc = rb_errinfo();
    if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit))
        showExc(exc);

    ruby_cleanup(0);

    shState->rtData().rqTermAck = true;
}

And that gave me this error output:

<main>: [BUG] Segmentation fault
ruby 2.0.0p481 (2014-05-08 revision 45883) [i386-mingw32]

-- Control frame information -----------------------------------------------
c:0001 p:0000 s:0002 E:0019a4 TOP    [FINISH]

-- C level backtrace information -------------------------------------------
C:\Windows\SYSTEM32\ntdll.dll(NtWaitForSingleObject+0xc) [0x770ED1BC]
C:\Windows\SYSTEM32\KERNELBASE.dll(WaitForSingleObject+0x12) [0x7609103D]
G:\Pokemon_NoxMK\msvcrt-ruby200.dll(nl_langinfo_codeset+0xcecd3) [0x66925477]
G:\Pokemon_NoxMK\msvcrt-ruby200.dll(Init_File+0xb60) [0x667D075C] g:\ruby-2.0.0-
p481\file.c:5725
G:\Pokemon_NoxMK\msvcrt-ruby200.dll(nl_langinfo_codeset+0x670ec) [0x668BD890]
G:\Pokemon_NoxMK\msvcrt-ruby200.dll(rb_file_expand_path+0x14) [0x667D151E] g:\ru
by-2.0.0-p481\file.c:3317
G:\Pokemon_NoxMK\msvcrt-ruby200.dll(nl_langinfo_codeset+0x4bffc) [0x668A27A0]
C:\Windows\SYSTEM32\msvcrt.dll(XcptFilter+0x14e) [0x7621F630]
C:\Windows\SYSTEM32\msvcrt.dll(libm_sse2_tan_precise+0x11bdc) [0x76201CF7]
C:\Windows\SYSTEM32\msvcrt.dll(beginthreadex+0xc7) [0x761B0CEC]
C:\Windows\SYSTEM32\KERNEL32.DLL(BaseThreadInitThunk+0xe) [0x75F6919F]
C:\Windows\SYSTEM32\ntdll.dll(RtlInitializeExceptionChain+0x84) [0x770FA8CB]

-- Other runtime information -----------------------------------------------
cremno commented 9 years ago

What about this?

static void mriBindingExecute()
{
    int argc;
    char **argv;
    ruby_sysinit(&argc, &argv);
    ruby_setup();

I can't test it at the moment. I hope you don't mind that you have to test my guesses!

khkramer commented 9 years ago

Of course I don't mind, you're trying to help me out here.

EDIT: That worked like a charm, thank you very much.

Ancurio commented 9 years ago

Is it okay to pass uninitialized variables into ruby_sysinit?

Also,

/*! Initializes the process for ruby(1).
*
* This function assumes this process is ruby(1) and it has just started.
* Usually programs that embeds CRuby interpreter should not call this function,
* and should do their own initialization.
*/

I guess this doesn't make much sense to include in master then?

cremno commented 9 years ago

ruby_sysinit needs to be called. At least on Windows, because it calls rb_w32_sysinit.

khkramer commented 9 years ago

The RMX-OS Input module also seems to be broken, even after I've already fixed all Win32-api calls.

I'm not getting any errors or warnings whatsoever though.

It should actually be compatible with Ruby 2.0 so that shouldn't be the problem, since it also worked with ARC.

Ancurio commented 9 years ago

Hm, how did you "fix" the Win32API calls? Did you use equivalent Xlib calls instead?

khkramer commented 9 years ago

I used the win32-api gem, as I'm currently still on windows only.

Ancurio commented 9 years ago

Ohh, right, forgot you're on windows. My bad.

Maybe there's a difference in how RMXP's player sets up its window compared to mkxp (SDL2), but I'm not familiar with Windows development at all unfortunately.

khkramer commented 9 years ago

It seems to be the input module does not allow 'overwriting' it I think, when I aliased the update method adding a call to the rmxos's input module update method it worked, however this is a far from ideal solution.

Ancurio commented 9 years ago

So I stubbed out the Win32API class and made an Input.update call in the main script, and it did call the correct overwritten RMX-OS Input::update function. Very weird =/

khkramer commented 9 years ago

Fixed that issue, but can't seem to get the method working that gets an input string.

This method is pretty vital as it's used for the login/register screen and the chat.

It's also in the RMX-OS Input module.