ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.2k stars 516 forks source link

Some but not all void* values explode when accessed in lua. #1402

Open onelumin opened 2 years ago

onelumin commented 2 years ago

I have a little carrier struct like this:

struct holder {
    void* id;
};

With a usertype binding:

state.new_usertype<holder>(
    "holder", sol::constructors<holder()>(),
    "id", &holder::id
);

If I default construct it in lua like this:

print(holder.new().id)

I get: userdata: NULL. great!

But when id happens to = 0x612f93000000004e before calling id for instance,

I get: libc++abi: terminating due to uncaught foreign exception. not so great.

In my case, this void* happens to point into some vulkan gpu memory magic which should never be interacted with by any lua stuff.

This happens in sol::stack::unqualified_pusher<void*, void>::push(lua_State*, void*)

Since the error depends on the value of the pointer, can I stop sol from touching it completely?