Jump to content

GetMaterial returns NULL


gamecreator
 Share

Recommended Posts

Thanks. I think this did come up before.

 

It is a little confusing though since the example on this page does it a lot like I did.

http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitygetmaterial-r127'>http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitygetmaterial-r127

 

Material* material = entity->GetMaterial();

 

Also, GetMaterial is one of the functions on the Entity page.

http://www.leadwerks.com/werkspace/page/api-reference/_/entity/

Link to comment
Share on other sites

I tried

 

Material* material = player.model->GetSurface(0)->GetMaterial();

 

And it crashed the program. The console said "Error: Surface index out of range."

 

I tried GetSurface(1) and same thing.

 

Then I thought maybe I need to get a child first, which seems reasonable, even though the GetSurface example on the Barbarian model doesn't do that.

 

Material* material = player.model->GetChild(1)->GetSurface(0)->GetMaterial();

 

which got me

 

Error 12 error C2227: left of '->GetMaterial' must point to class/struct/union/generic type

Error 11 error C2039: 'GetSurface' : is not a member of 'Leadwerks::Entity'

 

Thoughts?

Link to comment
Share on other sites

Thanks! That worked. It's still crashing when I try to implement it in the SetPixels example but I'll take a moment to try to figure that one out.

 

I noticed when implementing a system today that even on some surfaces GetMaterial() returns null.... So I guess some surfaces simply don't have materials on them, just check and make sure 'Surface::GetMaterial() != NULL'.

 

I noticed this in a similar situation, when I was relying on the fact that Surface::GetMaterial() never returned null, when in fact it does in many cases so I had some crashing til I did a check to make sure the returned value isn't NULL, now I'm getting the expected behavior.

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