martyj Posted January 11, 2015 Share Posted January 11, 2015 I have an Entity object passed from lua code via lua_touserdata int Binder::RegisterClass(lua_State* L) { Entity* entity = (Entity*)lua_touserdata(L, 1); const char* className_cstr = lua_tostring(L, 2); string className(className_cstr); Vec3 posit = entity->GetPosition(); } The Lua code that calls this C code function Script:Start() WorldFactions.RegisterClass(self.entity, "AnimatedModel"); end I get an access violation on the line that is Vec3 posit = entity->GetPosition(); Below is a screenshot of the breakpoint on the same line before execution. Quote Link to comment Share on other sites More sharing options...
MarkusR Posted January 12, 2015 Share Posted January 12, 2015 the last problem i had with .GetPosition() it was this csg objects from toolbar made problem without have a script, it was not a entity object and something else i believe. Quote PC : Win 10 Pro 64 Bit , 4x cores ~2 GHz , 8 GB RAM , AMD R7 265 2D : Photoline , Zooner Photo Studio 13 , Art Rage Studio 3.5.4 , Ashampoo Snap 7 , ... 3D : Shade 15 Basic , Carrara 8.5 & DAZ Studio 4.8 , Cheetah 3D 6.3.2 , Via Cad 8 Music : Samplitude Music Studio , Music Creator 7 IDE : Leadwerks Engine 3.x , Unity 5.x , (Unreal 4.8.x) , AGK v2.x , Construct 2 , (Clickteam Fusion 2.5) , ShiVa 1.9 , Game Maker Studio , MS Visual Studio .Net , Android Studio , Monkey , ... Link to comment Share on other sites More sharing options...
martyj Posted January 12, 2015 Author Share Posted January 12, 2015 This object should be an Entity type considering how I am calling my C code from Lua. Unless I am passing the params wrong, the string passes correctly. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 12, 2015 Share Posted January 12, 2015 Any chance it is a CSG brush? Those get collapsed on scene loading for performace. Only when a script is attached these remain entities. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 12, 2015 Share Posted January 12, 2015 Any chance it is a CSG brush? Those get collapsed on scene loading for performace. Only when a script is attached these remain entities. That's what I thought at first but he's passing self.entity inside an entity script (because of Script:Start() shown) which means even if it was it has a script attached to it which would prevent the collapse. I'm not 100% sure if the Lua entity can be translated to an Entity in C++. You might want to try just passing it's string name and then in C++ find it via it's name for testing purposes. Of course this means each name has to be unique (which I'm a proponent for personally anyway). Quote Link to comment Share on other sites More sharing options...
Ma-Shell Posted January 12, 2015 Share Posted January 12, 2015 I would guess as well that the LUA entity is not directly compatible with a C++-Entity (as Rick suggested). Your screenshot shows that the attributes have some rubbish values. So that object you are inspecting surely isn't a C++-Entity. Maybe there is a bit of an offset needed. I would try implementing the method Rick suggested and then looking at the different addresses the two methods yield and whether they are in any way coherent. Quote Link to comment Share on other sites More sharing options...
martyj Posted January 13, 2015 Author Share Posted January 13, 2015 Thanks for the feedback guys. I will try Rick's suggestion. It should work without any problems. Quote Link to comment Share on other sites More sharing options...
Chimera Posted January 28, 2015 Share Posted January 28, 2015 I am also getting an access violation when using the ->SetPosition/Fov commands in C++. Code in question(Posting the entire App::Start for completeness' sake) : bool App::Start() { //Perform cfg checks. Sets screenres to 1920x1080 if they throw an error try { ScreenWidth = stoi(System::GetProperty("Screen Width", "1920")); ScreenHeight = stoi(System::GetProperty("Screen Height", "1080")); } catch (std::invalid_argument) {std::cout << "\n\nWaiter!!! There was a string in my Screen Res!\n\n";} //Initialize Steamworks (optional) if (!Steamworks::Initialize()) { System::Print("Error: Failed to initialize Steam."); return false; } //Create a window window = Leadwerks::Window::Create("Game Window",0,0,ScreenWidth,ScreenHeight,Window::Titlebar); //Create a context context = Context::Create(window); //Create a world world = World::Create(); std::string mapname = System::GetProperty("map","Maps/G.map"); Map::Load(mapname); //The culprits are right here-----> //cam->SetPosition(0, 5, 0); //cam->SetFOV(90); //Move the mouse to the center of the screen window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2); window->HideMouse(); return true; } I have tried debuging multiple times, and it always throws an access violation when those 2 lines are uncommented. It works perfectly fine if I just create a camera through the editor though, so I have no clue what is going on. EDIT: Apparently my problem was I forgot to call Camera::Create on cam....... I am an idiot. ಠ_ಠ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.