dragome/dragome-sdk

New code fail to compare class type

Closed this issue · 27 comments

dont work

Toke me a while to find this.

type2 have interfacesCache while type doesn't

I cannot find a way to reproduce it. Looking at class forName method I dont see any place where realName property could take those different values. Are you sure you are using last Class implementation?
Could you paste generated code of Class.forName method?

I used the last commit. Set up scene2d ui libgdx test and you will catch these problems easier because it use json e reflection alot.

I remember that the compare was failing (both types should be equal). Is it because type dont have interfacesCache object or for some reason type was created and didn't use the same pointer as type2 ?

Hi @fpetrola . I commited UITest so its easier for you to take a look if you already have dragome backend set.

This is not the only error, there are more. Take a look at my last commit 32ab595

I'm not able to compile master branch, did you commit ApplicationLogger class?

@fpetrola are you using libgdx nightlies ? I use the most updated libgdx commit.

I'm using maven dependency, last release is this: https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx/1.9.4
Do you know if there is any SNAPSHOT version available?

I'm trying to use version 1.9.6-SNAPSHOT but there are some bugs introduced in this particular version I guess. Such as a wrong regexp and absent font.

I solved regexp problem with a temporal patch, but I still have this problem:

webapp.js:17385 Uncaught construct$$$cause___java_lang_Throwable: construct$$$message___java_lang_String: "Missing: file"message: "Missing: file"proto: construct$$$message___java_lang_String: "Error loading font file: com/badlogic/gdx/utils/arial-15.fnt"message: "Error loading font file: com/badlogic/gdx/utils/arial-15.fnt"stack: undefined__proto__: construct$$init____java_lang_String$void: (message)$$init____java_lang_String__java_lang_Throwable$void: (message,t)$$init____java_lang_Throwable$void: (t)basename: "com_badlogic_gdx_utils_GdxRuntimeException"classname: "com_badlogic_gdx_utils_GdxRuntimeException"constructor: [Class com_badlogic_gdx_utils_GdxRuntimeException]name: "com_badlogic_gdx_utils_GdxRuntimeException"proto: construct

Any idea?

I downgraded to 1.9.4 and I'm able to compile tests. Running UITest is throwing an undefined instance problem here:

r3 = new com_badlogic_gdx_graphics_g2d_TextureAtlas$TextureAtlasData$Page();
__r7 = __r9.$isMipMap$boolean();

But I dont know if it's related to type comparison problem, I need to reproduce it to be able to give a fix.

Former problem is related to this exception:

Exception:
construct
$$$message___java_lang_String:"Font file not found: data/default.fnt"
message:"Font file not found: data/default.fnt"

forgot to add default but thats not the problem. I tried again and I remember that it had 2 errors. the first I did a dirty hack to make it work (lost the code)

image

If you look at the picture above ( "$$$" + name ) should be changed.

And the 2nd error is the compare problem.

@fpetrola quick fix in enum class

public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
	{
		ScriptHelper.put("enumType", enumType, null);
		ScriptHelper.put("name", name, null);
		ScriptHelper.evalNoResult("var obj=enumType.$$$nativeClass___java_lang_Object.$$clinit_()", null);
		ScriptHelper.evalNoResult("var base='___'+obj.basename", null);
		ScriptHelper.evalNoResult("var finalPath='$$$'+name+base", null);
		return (T) ScriptHelper.eval("obj[finalPath]", null);
	}

But seems new errors pop up after this fix (regex)

I went back to 1.9.4. because of the regex error. Reverted dragome tests changes (Logger and Animation) from 1.9.5 and I managed to reproduce the compare error again.

The compare happens in https://github.com/libgdx/libgdx/blob/9b8f20b2d0e96e53f0f2b98dc8f6131c810aae71/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Skin.java#L144-L158

I replaced the code to

public <T> T get (String name, Class<T> type) {
		if (name == null) throw new IllegalArgumentException("name cannot be null.");
		if (type == null) throw new IllegalArgumentException("type cannot be null.");


		Class<Drawable> type2 = Drawable.class;

		if (type == type2) {
			System.out.println("Equal");
		}
		else {
			System.out.println("Not Equal");
		}

		if (type == Drawable.class) return (T)getDrawable(name);
		if (type == TextureRegion.class) return (T)getRegion(name);
		if (type == NinePatch.class) return (T)getPatch(name);
		if (type == Sprite.class) return (T)getSprite(name);

		ObjectMap<String, Object> typeResources = resources.get(type);
		if (typeResources == null) throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
		Object resource = typeResources.get(name);
		if (resource == null) throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
		return (T)resource;
	}

So its easier find and to breakpoint in chrome but you can add breakpoint directly without skin changes. Just find the "get" method in Skin class.

When you get it right you will get a "Error reading file: data/uiskin.json" error with "Not Equal" printed in the console if you replaced the code.

image

I've commit the valueof fix (a6f4874).
Breakpoint in "get" method is not working yet cause default.fnt problem is interrupting execution before it. How can I fix it?

I've tried putting a default.fnt in data folder and gdx is not able to find it:

FileHandle internal = Gdx.files.internal("data/default.fnt");
boolean exists = internal.exists();

exists = false

Download default.png and default.fnt from here https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests-android/assets/data
and put them in "gdx-tests-dragome/webapp/assets/data/".

In "gdx-tests-dragome/src/com/badlogic/gdx/tests/dragome/launcher/UITestLauncher.java" add the code below inside "createApplicationListener" method

getPreloader().loadAsset("data/default.fnt", AssetType.Text, null, new AssetLoaderListener<Object>());
getPreloader().loadAsset("data/default.png", AssetType.Image, null, new AssetLoaderListener<Object>());

I'll commit these changes when I get home.

fnt and png added, but there are still problems:
"No com.badlogic.gdx.scenes.scene2d.utils.Drawable registered with name: default-round-down"

Dont have my pc right know to see if its the same error log. Is "get" method in skin class (javascript) getting called before the error occur ?

no it dont, current error is thrown in skin initialization: data/uiskin.json loading

I remember error logs show "Error reading file: data/uiskin.json" after passing through "get" method.

Something is failing somewhere. alot of breakpoins to go deep and know the cause. Is proguard turned off ? Can you send me your generated javascript ?

default-round-down is defined in uiskin.atlas, does it require to be loaded before skin?
The stacktrace is:

com_badlogic_gdx_scenes_scene2d_ui_Skin.prototype.$get___java_lang_String__java_lang_Class$java_lang_Object() (webapp.js:formatted:112947)
com_badlogic_gdx_scenes_scene2d_ui_Skin$1.prototype.$readValue___java_lang_Class__java_lang_Class__com_badlogic_gdx_utils_JsonValue$java_lang_Object() (webapp.js:formatted:112312)
com_badlogic_gdx_utils_Json.prototype.$readFields___java_lang_Object__com_badlogic_gdx_utils_JsonValue$void() (webapp.js:formatted:111002)
com_badlogic_gdx_utils_Json.prototype.$readValue___java_lang_Class__java_lang_Class__com_badlogic_gdx_utils_JsonValue$java_lang_Object() (webapp.js:formatted:111366)
com_badlogic_gdx_scenes_scene2d_ui_Skin$1.prototype.$readValue___java_lang_Class__java_lang_Class__com_badlogic_gdx_utils_JsonValue$java_lang_Object() (webapp.js:formatted:112310)
com_badlogic_gdx_utils_Json.prototype.$readValue___java_lang_Class__com_badlogic_gdx_utils_JsonValue$java_lang_Object() (webapp.js:formatted:111099)
com_badlogic_gdx_scenes_scene2d_ui_Skin$2.prototype.$readNamedObjects___com_badlogic_gdx_utils_Json__java_lang_Class__com_badlogic_gdx_utils_JsonValue$void() (webapp.js:formatted:112444)
com_badlogic_gdx_scenes_scene2d_ui_Skin$2.prototype.$read___com_badlogic_gdx_utils_Json__com_badlogic_gdx_utils_JsonValue__java_lang_Class$com_badlogic_gdx_scenes_scene2d_ui_Skin() (webapp.js:formatted:112393)
com_badlogic_gdx_scenes_scene2d_ui_Skin$2.prototype.$read___com_badlogic_gdx_utils_Json__com_badlogic_gdx_utils_JsonValue__java_lang_Class$java_lang_Object() (webapp.js:formatted:112513)
com_badlogic_gdx_utils_Json.prototype.$readValue___java_lang_Class__java_lang_Class__com_badlogic_gdx_utils_JsonValue$java_lang_Object() (webapp.js:formatted:111221)
com_badlogic_gdx_scenes_scene2d_ui_Skin$1.prototype.$readValue___java_lang_Class__java_lang_Class__com_badlogic_gdx_utils_JsonValue$java_lang_Object() (webapp.js:formatted:112310)
com_badlogic_gdx_utils_Json.prototype.$fromJson___java_lang_Class__com_badlogic_gdx_files_FileHandle$java_lang_Object() (webapp.js:formatted:110922)
com_badlogic_gdx_scenes_scene2d_ui_Skin.prototype.$load___com_badlogic_gdx_files_FileHandle$void() (webapp.js:formatted:112781)
com_badlogic_gdx_scenes_scene2d_ui_Skin.prototype.$$init____com_badlogic_gdx_files_FileHandle$void() (webapp.js:formatted:112774)
com_badlogic_gdx_tests_dragome_examples_UITest.prototype.$create$void() (webapp.js:formatted:71237)
com_badlogic_gdx_backends_dragome_DragomeApplication$2$1.prototype.onready() (webapp.js:formatted:19900)
onready (webapp.js:formatted:16015)
P (VM36171:91)
(anonymous) (VM36171:92)

Proguard was enabled, but disabling it the same problem appears.

ah ok! It's entering to "get" method, I thought the bug was thrown in line 66, but it's in Skin creation.
Now I can reproduce the issue!

Okay =) . Now compare if Drawable.class and the parameter type Drawable is equal or not equal.