Jump to content
  • Advertisement
Sign in to follow this  
B_old

2.17.2 WARNING: A non-const method is called on temporary object

This topic is 3340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, after upgrading to version 2.17.2 (from 2.17.0) I get the following warning in one script "WARNING: A non-const method is called on temporary object. Changes to the object may be lost.". I don't really understand what temporary object is supposed to cause the problem. Any idea what this could be about?
class FloatingSphere
{
	Vector3 m_anchor;
	Vector3 m_destination;
	Vector3 m_dir;
	float   m_range;
	
	void init(const Vector3 &in anchor, float range)
	{
		m_anchor = m_destination = anchor;
		m_range = range;
	}
	
	
	void update(Object @object, float speed)
	{
                //somewhere in this method the warning appears twice


		float d = distance(m_destination, object.getWorldPos());
		
		
		if (d < 0.05f)
		{
			m_destination = m_anchor + m_range * randomVector();
			m_dir = normalized(m_destination - object.getWorldPos());
		}
			
			
		object.setPos(object.getWorldPos() + 0.2f * min(2.f * d / m_range, 1.f) * speed * m_dir);	
			

		object.updateTransform();
	}
	
	
	Vector3 randomVector() const
	{
		return normalized(Vector3(rand(-1.f, 1.f), rand(-1.f, 1.f), rand(-1.f, 1.f)));
	}
};

Share this post


Link to post
Share on other sites
Advertisement
Thanks for the hint. :) I forgot a little const when registering the operator overload with angelscript.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!