Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

passing object pointer to function and change values?

4: Adsense

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   

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


Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me


#2 Álvaro   Members   

20931
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   

4970
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


Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me





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.