BUG: CCMutableDictionary::setObject fails if object already exists

BUG: CCMutableDictionary::setObject fails if object already exists
0.0 0


This function uses map::insert to insert the given object in the dictionary. However, if an object with that key already exists, insert will have no effect. So for example, the following assert will fire:

CCString s1 = new CCString;
s2 = new CCString(“string2”);

CCMutableDictionary<std::string, CCString*> dict;
dict.setObject(s1, “test”);
dict.setObject(s2, “test”);
CC_ASSERT(dict.objectForKey(“test”) == s2 && “setObject failed!”);


I think we want this result, isn’t it?


Sorry for the late reply.

I would have thought that setObject should always have an effect. In this case, it will have no effect on the second call. I would have expected the object to have been set, both times, but the second time it isn’t. I believe the cocoa class NSMutableDictionary would not have fired the assert in my snippet there, and isn’t it supposed to have the same behaviour as CCMutableDictionary?


The assert is only has effect on debug mode. It tells you that you may have an error.


Yes, I understand this. My point is that the assert should not fire, as after the line

dict.setObject(s2, “test”);

I would expect

dict.objectForKey(“test”) == s2

to be true. But it isn’t.