sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

value is a userdata but is not the correct unique usertype on MSVC

Open lhog opened this issue 4 years ago • 1 comments

Hi ThePhD!

I'm on https://github.com/ThePhD/sol2/commit/f56b3c69

Config:

#define LUA_VERSION_NUM 501
#define SOL_USING_CXX_LUA 1
#define SOL_ALL_SAFETIES_ON 1
#define SOL_NO_CHECK_NUMBER_PRECISION 1

Usertypes:

sol::state_view lua(L);
auto gl = sol::stack::get<sol::table>(L, -1);

gl.new_usertype<LuaVAOImpl>("VAO",
	sol::constructors<LuaVAOImpl()>(),
	"Delete", &LuaVAOImpl::Delete,

	"AttachVertexBuffer", &LuaVAOImpl::AttachVertexBuffer,
	"AttachInstanceBuffer", &LuaVAOImpl::AttachInstanceBuffer,
	"AttachIndexBuffer", &LuaVAOImpl::AttachIndexBuffer,

	"DrawArrays", &LuaVAOImpl::DrawArrays,
	"DrawElements", &LuaVAOImpl::DrawElements
);
gl.new_usertype<LuaVBOImpl>("VBO",
	sol::constructors<LuaVBOImpl(const sol::optional<GLenum>, const sol::optional<bool>)>(),
	"Delete", &LuaVBOImpl::Delete,

	"Define", &LuaVBOImpl::Define,
	"Upload", &LuaVBOImpl::Upload,
	"Download", &LuaVBOImpl::Download,

	"ShapeFromUnitDefID", &LuaVBOImpl::ShapeFromUnitDefID,
	"ShapeFromFeatureDefID", &LuaVBOImpl::ShapeFromFeatureDefID,
	"ShapeFromUnitID", &LuaVBOImpl::ShapeFromUnitID,
	"ShapeFromFeatureID", &LuaVBOImpl::ShapeFromFeatureID,

	"OffsetFromUnitDefID", &LuaVBOImpl::OffsetFromUnitDefID,
	"OffsetFromFeatureDefID", &LuaVBOImpl::OffsetFromFeatureDefID,
	"OffsetFromUnitID", &LuaVBOImpl::OffsetFromUnitID,
	"OffsetFromFeatureID", &LuaVBOImpl::OffsetFromFeatureID,

	"BindBufferRange", &LuaVBOImpl::BindBufferRange,
	"UnbindBufferRange", &LuaVBOImpl::UnbindBufferRange,

	"DumpDefinition", &LuaVBOImpl::DumpDefinition,
	"GetBufferSize", &LuaVBOImpl::GetBufferSize
);
void LuaVAOImpl::AttachVertexBuffer(const std::shared_ptr<LuaVBOImpl>& luaVBO) {
	//something
}

It works great under GCC++, but fails under MSVC when AttachVertexBuffer is called from a script with stack index 2, expected userdata, received sol.sol::d::u<LuaVBOImpl>: value is a userdata but is not the correct unique usertype (bad argument into 'void(const std::shared_ptr<LuaVBOImpl>&)')

MSVC: Microsoft Visual Studio Community 2019 Version 16.9.5

Any way to work it around?

lhog avatar May 29 '21 19:05 lhog

Got to it today again and I only ended up making it work with:

using whetever = std::shared_ptr<LuaVBOImpl>; and replacing all the occasions of std::shared_ptr<LuaVBOImpl> with whetever. The error message is gone, however I'm not 100% sure that what I did is legit.

lhog avatar Jul 17 '21 19:07 lhog