• Advertisement
Sign in to follow this  

Weird string behavior when using ?:

This topic is 498 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

Encountered a weird behavior in string addition today on the latest SVN build:
 
string foo = "foo" + (true ? string("bar") : "bar");
string bar = "foo" + (false ? "bar" : string("bar"));
string foobar = "foo" + (true ? "bar" : "bar");
print(foo); // barbar
print(bar); // foobar
print(foobar); // foobar
The obviously-broken case here is the first one, which turns into "barbar". I wasn't able to reproduce this with integers or a simple script class with an opAdd method, so perhaps this is exclusive to the scriptstdstring addon?

Share this post


Link to post
Share on other sites
Advertisement

Probably not a problem with the scriptstdstring add-on but rather a specific case for registered value types.

 

I'll investigate it and have it fixed as soon as possible.

Share this post


Link to post
Share on other sites
Just ran into another string-related issue, perhaps it's related. The following never passes:
 
if (wButton.m_func == "scenario " + m_currentScenario.GetID())
Neither does this:
 
string id = m_currentScenario.GetID();
if (wButton.m_func == "scenario " + id)
But this DOES pass:
 
string id = "scenario " + m_currentScenario.GetID();
if (wButton.m_func == id)
Here, wButton.m_func is defined in scripts, and GetID() is a method registered by C++ with declaration "string GetID()".

This seemed to have started happening after updating the WIP SVN version (we were already using the WIP version before but we were a little behind).

Share this post


Link to post
Share on other sites

I've fixed this now in revision 2368.

 

All of the scenarios were caused by the same bug. A temporary variable was being overwritten when invoking overloaded operators with left-to-right evaluation. This bug was introduced in the WIP itself. Good thing you identified the problem before I released the new version. :)

Share this post


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

  • Advertisement