Jump to content

Crash with CameraPick


AggrorJorn
 Share

Recommended Posts

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");
						}
					}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

post-45-0-56322000-1333545481.jpg

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

post-45-0-68683400-1333559495.jpg

 

After clicking on the 2 green arrows, it shows this:

post-45-0-02163600-1333559501_thumb.jpg

 

*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 by Aggror
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...