OSDN Git Service

Added work around for bug 155 in RoboVM which may cause ClassCastExceptions to be...
authorNiklas Therning <niklas@therning.org>
Fri, 13 Sep 2013 16:13:04 +0000 (18:13 +0200)
committerNiklas Therning <niklas@therning.org>
Fri, 13 Sep 2013 16:13:04 +0000 (18:13 +0200)
backends/gdx-backend-robovm/src/com/badlogic/gdx/backends/iosrobovm/IOSPreferences.java

index 263d3cb..c392565 100644 (file)
@@ -8,12 +8,21 @@ import org.robovm.cocoatouch.foundation.NSMutableDictionary;
 import org.robovm.cocoatouch.foundation.NSNumber;
 import org.robovm.cocoatouch.foundation.NSObject;
 import org.robovm.cocoatouch.foundation.NSString;
+import org.robovm.objc.ObjCClass;
 
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Preferences;
 
 public class IOSPreferences implements Preferences {
 
+       static {
+               // FIXME: Work around for a bug in RoboVM (https://github.com/robovm/robovm/issues/155).
+               //        These calls make sure NSNumber and NSString have been registered properly with the
+               //        RoboVM Objective-C bridge. Without them the get-methods below may throw ClassCastException.
+               ObjCClass.getByType(NSNumber.class);
+               ObjCClass.getByType(NSString.class);
+       }
+       
        NSMutableDictionary<NSString, NSObject> nsDictionary;
        String filePath;