gpt4 book ai didi

java - Libgdx JsonWriter StackOverflowError 错误

转载 作者:太空宇宙 更新时间:2023-11-04 07:51:19 26 4
gpt4 key购买 nike

尝试使用基于 jsonbeanscom.badlogic.gdx.utils.Json 将对象写入 json 时,出现 StackOverflowError 错误。 。该对象及其引用的所有对象仅包含原始变量,如 float、boolean、int 等,但对 ShapeRenderer 的引用除外。多个对象都引用同一个 ShapeRenderer。有一些循环引用(对象都互相引用),但我认为它应该能够处理这个问题。

导致这些错误的原因是什么?循环引用有问题吗?我不能简单地删除它们而不返回绘图板并重组我的应用程序的主要部分。

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)

不确定这是日志限制还是堆栈限制,我猜是第一个。

最佳答案

循环引用是问题所在。这是一个不错的Solution :

I think the best way to address this is, is to probably remove your circular link by re-architeching your data structure in some way, maybe using some sort of map or table instead to link the Entity to the Item.

If you really must keep the circular references, then I'd recommend writing your own parser as simply ignoring the owner on serialization will mean the owner is not returned when the serialized objects are deserialized.

关于java - Libgdx JsonWriter StackOverflowError 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14424071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com