Jump to content

  • Log In with Google      Sign In   
  • Create Account

passing object pointer to function and change values?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 cozzie   Members   -  Reputation: 1762

Like
0Likes
Like

Posted 28 February 2013 - 04:03 PM

Hi,

I'm passing an object of my class to a function as a pointer.

When I try to access and change one of the members of the passed object, I get access violations.

Am I overseeing something?

 

The code:

 

bool CD3d::LoadScene(CScene *pScene, CD3dscene *pD3dscene, CD3dcam *pCam)
{
		pScene->mEffectFilenames[0] += ShaderSelectOptimalGeneric(pD3dscene, &nrdirlights, &nrpointlights);
		pD3dscene->mShaders[0].SetLightCount(0, 1); //nrdirlights, nrpointlights);
}										

On the 2nd line it goes wrong.

Looks like within the function I'm only allowed to read from the passed object, even though I'm using a pointer to the object

(I've checked through debugging that mShaders[0] exists and is valid)



Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13907

Like
0Likes
Like

Posted 28 February 2013 - 04:14 PM

What do you mean by "access violations"? As in "you are trying to access private parts of the class" or "you are trying to access memory out of range"? What's the error message?

 

EDIT: Never mind. You used a debugger, which means that the compiler didn't complain.


Edited by Álvaro, 28 February 2013 - 04:15 PM.


#3 cozzie   Members   -  Reputation: 1762

Like
0Likes
Like

Posted 28 February 2013 - 04:17 PM

sorry, got it.

The mShaders[0] was not created yet )-;

 

Time to clean up memory allocation/ bundle them in a separate function.

thanks for the help






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS