AggrorJorn Posted April 4, 2012 Share Posted April 4, 2012 I am trying to get a 3d position using a CameraPick. Unfortunately, when the pick hits something, it crashes the programm as soon as it uses the pick position for placing an entity. The values of the pick seem be ok. What could cause this? if (LE.MouseHit(Mousebuttons.MOUSE_LEFT)) { //LE.HideEntity(character); if (LE.CameraPick(out pick, camera, new TVec3(LE.MouseX(), LE.MouseY(), 1000), 0, 0, null) == 1) { Console.WriteLine("Hit something!"); Console.WriteLine("1:: " + pick.X.ToString() + " " + pick.Y.ToString() + " " + pick.Z.ToString()); LE.PositionEntity(builder.bunker, new TVec3(pick.X, pick.Y + 0.25f, pick.Z)); } else { Console.WriteLine("didn't hit something"); } } Quote Link to comment Share on other sites More sharing options...
Rick Posted April 4, 2012 Share Posted April 4, 2012 builder.bunker is valid? Seems to be the only thing that could go wrong if those Console.WriteLine's are showing valid values, unless your error is somewhere else after but I assume you've stepped through the code and see that it fails on the PositionEntity() line. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 4, 2012 Author Share Posted April 4, 2012 Thanks for the reply. Yes, thats what I as thinking to. The bunker is valid though. Outside the if statement with the pick, I can do whatever I want. here is an exmaple: if (builder.bunker.IsValid) { Console.WriteLine("validation check"); LE.PositionEntity(builder.bunker, new TVec3(50,40,30))l; } if (LE.MouseHit(Mousebuttons.MOUSE_LEFT)) { //LE.HideEntity(character); if (LE.CameraPick(out pick, camera, new TVec3(LE.MouseX(), LE.MouseY(), 1000), 0, 0, null) == 1) { Console.WriteLine("Hit something!"); Console.WriteLine(pick.X.ToString() + " " + pick.Y.ToString() + " " + pick.Z.ToString()); if (builder.bunker.IsValid) { Console.WriteLine("is valid"); LE.PositionEntity(builder.bunker, new TVec3(pick.X, pick.Y + 0.25f, pick.Z)); } else Console.WriteLine("dero, something wrong with validation"); } With as result: Quote Link to comment Share on other sites More sharing options...
Rick Posted April 4, 2012 Share Posted April 4, 2012 That is showing me builder.bunker.IsValid is failing. So I would say builder.bunker isn't valid. Not sure why you think it is valid. "is valid" doesn't get printed and the else clause doesn't get printed. That tells me it's failing on the if clause because either builder or bunker isn't created (that's what the object reference now set to an instance of an object generally means). Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 4, 2012 Author Share Posted April 4, 2012 True, inside the pick if statement, it doesn't work. But before I click with my mouse I also check if the model is valid. And there is says that it is valid. The post kindof ruines the indenting of the code. That is why you can see the validation check message constantly. The model does get loaded as it can be seen in my program (when the picking is commented out). Quote Link to comment Share on other sites More sharing options...
Rick Posted April 4, 2012 Share Posted April 4, 2012 Is it maybe being garbage collected somewhere along the way? Are you stepping through this code or just relying on the console messages? Would be interesting to step through line by line and after each line mouse over the builder.bunker variable to see when exactly it gets unallocated because that's what looks like is happening. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 4, 2012 Author Share Posted April 4, 2012 (edited) good idea rick. As soon as I am inside the body of the if statement, something odd happens. I have never seen this before. Notice how the builder variable suddenly is grayed out. After clicking on the 2 green arrows, it shows this: *Edit Reasons for this to be happening could have been 'setting project to debug mode' and 'uncheck optimize code'. That didn't really help. Edited April 4, 2012 by Aggror Quote Link to comment Share on other sites More sharing options...
Rick Posted April 4, 2012 Share Posted April 4, 2012 Easy solution. Switch to C++ Sorry mate, I have never seen that either so not sure what's going on. Looks like some kind of .NET thing happening there but I've never ran across that issue before. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 5, 2012 Author Share Posted April 5, 2012 Easy solution. Switch to C++ hehe, who knows...i think I am going to wait with that till LE3. On the other hand, I find C# really comfortable. Thanks for the help Rick. I appreciate the effort. If I find something, I will update the post. Quote Link to comment Share on other sites More sharing options...
Rick Posted April 10, 2012 Share Posted April 10, 2012 You know I'm seeing strange stuff too. I tried doing some picking just on the terrain. The first time everything works fine, but if I click again it errors out: if (LE.MouseHit(Mousebuttons.MOUSE_LEFT)) { TPick pick; if (LE.CameraPick(out pick, camera, new TVec3(LE.MouseX(), LE.MouseY(), 1000), 0, 0, null) == 1) { Console.WriteLine("(" + pick.X.ToString() + ", " + pick.Y.ToString() + ", " + pick.Z.ToString() + ")"); } } I have this inside a Game::Run method. I get the "object not set ..." error but it's on the 'this' function (which would be the Game class instance itself, which I'm inside of at this point. It's almost like while I'm inside Game::Run, the Game instance is getting GC or something. Very odd. [EDIT] Looks like I'm getting that same "possibly optimized away", error that you are getting. [EDIT2] Interestingly enough, not sure if you tried this, but if you just run the exe it works for me. So for sure just something with debugging. Give this a try. Still playing with it, but at least this will get the express edition more like pro. http://stackoverflow.com/questions/2812423/how-to-switch-between-debug-and-release-in-visual-c-sharp-2010-express/2938880#2938880 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 10, 2012 Author Share Posted April 10, 2012 Hmm that is interessting. I want to try that tonight. I have written other code that can more or less do the same, but having a pick is a lot easier. 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.