Project

General

Profile

« Previous | Next » 

Revision 958a6e81

Added by Leszek Koltunski over 1 year ago

Very important bugfix for an issue which probably has been the reason for many mysterious behaviours in the past: the JsonReader class cannot be a singleton! Convert it into a normal 'instanced' class.
With it being a singleton there's a major issue: when we create a new TwistyObject from a JSON file (by, for example, going to PurchaseActivity) and then we come back to the old object (by, for example, going back to the main RubikActivity) - then the JsonReader inside the old object has read the new JSON file and thus many of the 'abstract' methods in the old TwistyObject (for example getShortName()) all of the sudden start returning new values!

View differences:

src/main/java/org/distorted/objectlib/json/JsonReader.java
78 78
  private ObjectStickerOverride[] mStickerOverrides;
79 79
  private float mPillowCoeff;
80 80

  
81
  private static JsonReader mThis;
82

  
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

  
85
  private JsonReader()
86
    {
87
    }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

  
91
  public static JsonReader getInstance()
92
    {
93
    if( mThis==null ) mThis = new JsonReader();
94
    return mThis;
95
    }
96

  
97 81
///////////////////////////////////////////////////////////////////////////////////////////////////
98 82

  
99 83
  private void parseMetadata1(JSONObject object) throws JSONException
src/main/java/org/distorted/objectlib/main/ObjectControl.java
763 763

  
764 764
///////////////////////////////////////////////////////////////////////////////////////////////////
765 765

  
766
    public void changeIfDifferent(int ordinal, String oldName, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
766
    public void changeIfDifferent(int ordinal, String newName, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
767 767
      {
768 768
      TwistyObject object = mPreRender.getObject();
769
      String newName = object==null ? "" : object.getShortName();
769
      String oldName = object==null ? "" : object.getShortName();
770 770

  
771 771
      if( !oldName.equals(newName) || mMeshState!=meshState || mIconMode!=iconMode )
772 772
        {
src/main/java/org/distorted/objectlib/main/TwistyObject.java
163 163
    {
164 164
    try
165 165
      {
166
      JsonReader reader = JsonReader.getInstance();
166
      JsonReader reader = new JsonReader();
167 167
      reader.parseJsonFile(jsonStream);
168 168
      setReader(reader);
169 169
      mNumLayers = reader.getNumLayers();

Also available in: Unified diff