Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc.

Reply
 
Thread Tools
Old 08-22-2012, 12:34 PM   #31
marooder86
Orbinaut
 
marooder86's Avatar
Default

Quote:
Originally Posted by Hlynkacg View Post
 as for the rest, I've been reading up on access violations (Yay! Google) and trying to figure out why Martins' AttitudeReference class can call vessel variables without crashing but LEM_AP can't.
Don't take my words about memory access violation for sure it was a pure guess since this as well as memory leaks are two most common errors while dealing with pointers. Also since I've mentioned memory leaks you did remember about deleting autopilot object didn't you ?

Quote:
I found the following lines in the class defthat I think are signifigant but I'm not sure.

Code:
class AttitudeReference {
public:
	AttitudeReference (const VESSEL *vessel);
	inline const VESSEL *GetVessel() const { return v; }
later on in the class there is

Code:
private:
	const VESSEL *v;
If this does what I think it does it assigns the handle "v" to whatever vessel a particular instance of AttitudeReference is assigned to.
No, you're wrong here, the function GetVessel() doesn't do anything to v pointer, it only provides access to it. Look at it's body, there's only one instuction there "return v;" and no other instructions messing with "v". You should also notice those mysterious "const" specifiers, they are very important. Read the eighth paragraph.

Quote:
ok new problem, sort of.

using the method I descrbed above I can only access functions that are members of the orbiter vessel class it's self.

what do I need to do to get access to SpiderLEM's functions?
You need to use pointer to SpiderLEM not VESSEL class or use casting since SpiderLEM inherits from VESSEL(shouldn't new addons be inherited from VESSEL3 by the way).

Quote:
[/COLOR]This is the error I get when I call a function unique to spider LEM from LEM_AP.

Code:
1>c:\users\hlynkacg\documents\visual studio 2010\projects\spiderlem\lem_autopilots.cpp(269): error C2662: 'SpiderLEM::StageSeparation' : cannot 'this' pointer from 'const SpiderLEM' to 'SpiderLEM &'
1>          Conversion loses qualifiers
You're violating 'const' protection here as far as I can tell. Your pointer to SpiderLEM is const protected and StageSeparation function doesn't respect that.
marooder86 is offline   Reply With Quote
Old 08-22-2012, 04:23 PM   #32
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default

Quote:
Originally Posted by marooder86 View Post
 You need to use pointer to SpiderLEM not VESSEL class or use casting since SpiderLEM inherits from VESSEL(shouldn't new addons be inherited from VESSEL3 by the way).
Figured out that I needed to replace "VESSEL" w/ "SpiderLEM" myself but what is casting?

Quote:
You're violating 'const' protection here as far as I can tell. Your pointer to SpiderLEM is const protected and StageSeparation function doesn't respect that.
I read the link you provided but I don't see what I violated.

v will always be the same vessel for a given instance of LEM_AP so it should be constant shouldn't it? "StageSeparation()" is a simple void function so I don't see how it would violate constant protection either.
Hlynkacg is offline   Reply With Quote
Old 08-22-2012, 08:43 PM   #33
marooder86
Orbinaut
 
marooder86's Avatar
Default

Quote:
Originally Posted by Hlynkacg View Post
 ...but what is casting?
It's a mechanism/language feature which is being used for explicit type conversions. I bet if you ask google it will provide you with lots of more elaborate explanations, but as you've figured out there's no need for using it here.
Quote:
v will always be the same vessel for a given instance of LEM_AP so it should be constant shouldn't it?
Well, yes but you have to remember that by placing const specifier before any variable/pointer you tell the compiler this variable cannot be altered, it can only be read and compiler will guard that. I don't want to go deeper into explanation or give any advice as I'm guilty of not using constant correctness mechanism very often in my own code but AFAIK only 'const' functions can work with 'const' variables so if "StageSeparation()" does something with "const SpiderLEM *v;" then it has to be constant too, and you do that by placing 'const' after parenthesis in function declaration.
Code:
type StageSeparation(/*parameters*/) const{}
marooder86 is offline   Reply With Quote
Old 08-22-2012, 08:50 PM   #34
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default

Well I already solved the problem (sort of) by simply making v not a constant.

As N_Molson said, a simple example, like a ShuttlePB with a class where are put the lift functions, would be invaluable.

I'd write it myself but I still have no clue what I'm doing.
Hlynkacg is offline   Reply With Quote
Thanked by:
Reply

  Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 11:54 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2007 - 2012, Orbiter-Forum.com. All rights reserved.