vancegroup / vr-jugglua

VR JuggLua: A Framework for VR Applications Combining Lua, OpenSceneGraph, and VR Juggler
Boost Software License 1.0
11 stars 11 forks source link

Crasher in osgwrapper_osg.dll #126

Closed lpberg closed 10 years ago

lpberg commented 10 years ago

This code crashes:


local getRoomToWorld = function()
    return RelativeTo.World:getInverseMatrix()
end

local transformMatrixRoomToWorld = function(v)
    return getRoomToWorld():preMult(v)
end

local forklift = MatrixTransform{
}

--get forklifts position (currently in room)
local room_pose = forklift.Matrix
--remove forlift from room
-- RelativeTo.Room:removeChild(forklift)
--"transform" the forklifts position with respect to the world
local world_pose = transformMatrixRoomToWorld(room_pose)
--update the position of the forklift to the world position
forklift.Matrix = world_pose
--add forklift to world
-- RelativeTo.World:addChild(forklift)

This code doesn't:


local getRoomToWorld = function()
    return RelativeTo.World:getInverseMatrix()
end

local transformMatrixRoomToWorld = function(v)
    return v * getRoomToWorld()
end

local forklift = MatrixTransform{
}

--get forklifts position (currently in room)
local room_pose = forklift.Matrix
--remove forlift from room
-- RelativeTo.Room:removeChild(forklift)
--"transform" the forklifts position with respect to the world
local world_pose = transformMatrixRoomToWorld(room_pose)
--update the position of the forklift to the world position
forklift.Matrix = world_pose
--add forklift to world
-- RelativeTo.World:addChild(forklift)

The local world_pose line is key here - removing it (and updating the setting line) doesn't crash.

rpavlik commented 10 years ago

OK, so the initial issue is that premult with matrices modifies, rather than returning the result - see this help info

void    preMult([IN] Matrixd x)

So, in the first one, local world_pose is void:

result = RelativeTo.World:getInverseMatrix():preMult(forklift.Matrix)

help(result)

-- Help:    
-- class = void

Which is obviously not a valid value to be setting for a Matrix property. That said, it shouldn't crash (but rather error out), but it does.

It must be specific to void, since other wrong-type assignments just error: (ugly error, but it's inside osgIntrospection)

MatrixTransform{}.Matrix = osg.Group()

-- vrjLua ERROR: Could not run provided Lua string.  Lua returned this error message: [string "MatrixTransform{}.Matrix = osg.Group()"]:1: [/home/rpavlik/src/vr-jugglua/third-party/osgLua/src/osgLua/Value_metamethod_members.cpp:197] cannot convert from type `PN3osg5GroupE' to type `const N3osg7MatrixdE &'

The matrix method makeIdentity also returns void. Thus, we can simplify the testcase further (and this will actually run in the command line, not just in the navtestbed):

osg.MatrixTransform().Matrix = osg.Matrixd():makeIdentity()

It's crashing inside of osgIntrospection, in convertArgument<osg::Matrixd const&> (line 42 in Utility)

So, a couple issues here: