當試圖將對象寫入json com.badlogic.gdx.utils.Json
(基於jsonbeans)時,我得到StackOverflowError
。除了對ShapeRenderer的引用外,它引用的對象和所有對象只包含像float,boolean,int等基本變量。多個對象都引用相同的ShapeRenderer。有一些循環引用(對象都相互引用),但我認爲它應該能夠處理。Libgdx JsonWriter StackOverflowError
這些錯誤的原因是什麼?循環引用了問題嗎?我不能簡單地刪除它們,而無需返回到繪圖板並重新構建應用程序的主要部分。
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.StackOverflowError
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:111)
Caused by: java.lang.StackOverflowError
at java.util.regex.Pattern$CharProperty$1.isSatisfiedBy(Unknown Source)
at java.util.regex.Pattern$7.isSatisfiedBy(Unknown Source)
at java.util.regex.Pattern$7.isSatisfiedBy(Unknown Source)
at java.util.regex.Pattern$7.isSatisfiedBy(Unknown Source)
at java.util.regex.Pattern$7.isSatisfiedBy(Unknown Source)
at java.util.regex.Pattern$CharProperty.match(Unknown Source)
at java.util.regex.Pattern$Curly.match0(Unknown Source)
at java.util.regex.Pattern$Curly.match(Unknown Source)
at java.util.regex.Pattern$CharProperty.match(Unknown Source)
at java.util.regex.Matcher.match(Unknown Source)
at java.util.regex.Matcher.matches(Unknown Source)
at com.badlogic.gdx.utils.JsonWriter$OutputType.quoteName(JsonWriter.java:174)
at com.badlogic.gdx.utils.JsonWriter.name(JsonWriter.java:46)
at com.badlogic.gdx.utils.JsonWriter.set(JsonWriter.java:113)
at com.badlogic.gdx.utils.Json.writeType(Json.java:574)
at com.badlogic.gdx.utils.Json.writeObjectStart(Json.java:533)
at com.badlogic.gdx.utils.Json.writeValue(Json.java:491)
at com.badlogic.gdx.utils.Json.writeFields(Json.java:237)
at com.badlogic.gdx.utils.Json.writeValue(Json.java:492)
at com.badlogic.gdx.utils.Json.writeFields(Json.java:237)
at com.badlogic.gdx.utils.Json.writeValue(Json.java:492)
at com.badlogic.gdx.utils.Json.writeFields(Json.java:237)
at com.badlogic.gdx.utils.Json.writeValue(Json.java:492)
at com.badlogic.gdx.utils.Json.writeFields(Json.java:237)
這正好爲約1024行:
at com.badlogic.gdx.utils.Json.writeValue(Json.java:492)
at com.badlogic.gdx.utils.Json.writeFields(Json.java:237)
不知道這是否是日誌限制或堆棧限制,我想第一個。
你可以試着將你想寫入的值修剪成一個小例子嗎?您可能能夠找出具體問題。我懷疑一個循環引用的小例子將揭露這個問題... –
我刪除了所有循環引用和對ShapeRenderer的所有引用。我將shaperenderer傳遞給需要渲染每個幀的對象的渲染函數,以及需要時用於直接從父對象獲取的其他一些變量。現在JSON作家和讀者工作,但我仍然不知道爲什麼它不會很好地循環引用。它不會很難被發現,只需存儲每個唯一實例的一個副本,並通過ID引用其餘的實例... – Hatagashira