Hello. I am working on a wrapper library for Steamworks v1.44 using just FFI. The library uses just pure FFI without custom-built binaries. This allows for easy maintenance and upgrades in the future. The source code is available here:
https://github.com/2dengine/sworks-ffi
The library works good, but I am having trouble with the callbacks mechanism behind Sworks. I managed to get it working on Love2D 64-bit, but I can't get it to work on 32-bit versions of Love2D. Note that the callbacks mechanism requires C++ which makes things messy but not impossible. Also note that I have tried to take struct packing into account between platforms. I use "jit.off(func, true)" for the function that triggers the Sworks callbacks.
On 32-bit versions of Love2D, I get a crash after a callback is triggered (see vt:Run1 and vt:Run2 which are supposed to be virtual functions)
Would appreciate any feedback as to why this works fine on 64-bit versions of Love2D but fails on 32-bit. I don't know much about FFI so any help is greatly appreciated. Thanks!
Further reading:
https://garry.tv/2016/11/01/steamworks-sdk/
Need help with FFI on 32 vs 64-bit versions of Love2d 11.2
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Need help with FFI on 32 vs 64-bit versions of Love2d 11.2
Last edited by ivan on Sat Dec 11, 2021 8:24 am, edited 2 times in total.
Re: Need help with FFI on 32 vs 64-bit versions of Love2d 11.2
Have you tried to run it on a "real" 32 bit OS? Maybe it's a pointer size issue. Just guessing though.
It's probably not relevant to your problem, but I'm pretty sure the cast from <event> to <event>* is not required.
ffi.new already returns a pointer to the allocated object.
uint8 is defined twice. These are already defined, btw. They are named uint8_t, int16_t, etc.
It's probably not relevant to your problem, but I'm pretty sure the cast from <event> to <event>* is not required.
Code: Select all
local ffi = require('ffi')
ffi.cdef("typedef struct Blah { int i; };")
local b = ffi.new("struct Blah")
local p = ffi.cast("struct Blah*", b)
assert(b == p) -- true
Code: Select all
ffi.cdef([[
typedef unsigned char uint8;
typedef unsigned char uint8;
typedef signed char int8;
typedef short int16;
...
Re: Need help with FFI on 32 vs 64-bit versions of Love2d 11.2
Hey Grump,
Thank you so much for taking a look at this. I'm not very good with C or FFI so any help is greatly appreciated.
Also, note that the 64-bit binaries work fine even with the callbacks enabled.
Note that events are C++ objects with inheritance and virtual functions.
Not really sure how to handle this otherwise.
Thank you so much for taking a look at this. I'm not very good with C or FFI so any help is greatly appreciated.
Have not tried that yet, everything works great, except for Steamworks' callbacks mechanism.Have you tried to run it on a "real" 32 bit OS? Maybe it's a pointer size issue. Just guessing though.
Also, note that the 64-bit binaries work fine even with the callbacks enabled.
I'm trying to cast a void pointer there, so without the asterisk * I get:ffi.new already returns a pointer to the allocated object.
Code: Select all
Error: utils/avatar/sworks/api.lua:697: bad argument #1 to 'cast' (invalid C type)
Not really sure how to handle this otherwise.
Good catch there, this should be fixed as of today!uint8 is defined twice.
Re: Need help with FFI on 32 vs 64-bit versions of Love2d 11.2
I'm asking because you haven't specified: are you using 32 bit DLLs with 32 bit executables?
Re: Need help with FFI on 32 vs 64-bit versions of Love2d 11.2
True, the code is hacky because we are faking C++ which is clearly unsupported by FFI.
Yes, 32 bit binaries (vanilla love2d and sworks) on a 64 bit OS.
Re: Need help with FFI on 32 vs 64-bit versions of Love2d 11.2
This looks dodgy to me:
Maybe try
Code: Select all
typedef unsigned char uint8;
typedef signed char int8;
typedef short int16;
typedef unsigned short uint16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
Code: Select all
typedef uint8_t uint8;
typedef int8_t int8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
Re: Need help with FFI on 32 vs 64-bit versions of Love2d 11.2
I tried your version and it still crashes at the same point: virtual function call at vt:Run1
Btw, I didn't come up with that definition, it comes from "steam_api_flat.h"
Btw, I didn't come up with that definition, it comes from "steam_api_flat.h"
Who is online
Users browsing this forum: Google [Bot] and 159 guests