-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: resolve issue when loading a world a second time #4829
fix: resolve issue when loading a world a second time #4829
Conversation
assetTypeManager.getAssetTypes().forEach(k -> { | ||
for (ResourceUrn urn : k.getLoadedAssetUrns()) { | ||
if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) { | ||
k.getAsset(urn).ifPresent(Asset::dispose); | ||
} | ||
} | ||
}); | ||
assetTypeManager.getAssetType(BlockFamilyDefinition.class).ifPresent(AssetType::disposeAll); | ||
assetTypeManager.getAssetType(Prefab.class).ifPresent(AssetType::disposeAll); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
umm must be a better way to clean this up 👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my main question here is: can we run the disposal code when we switch out of the game environment? Wouldn't that be a better match to the expected lifecycle of these assets?
engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public boolean step() { | ||
context.put(RenderingModuleRegistry.class, new RenderingModuleRegistry()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes this better as a LoadProcess instead of a Subsystem?
more explicit ordering of load processes? or we need a different context here than was available for any of the subsystem lifecycle phases?
(and heck it is a lot of lines of code for these two expressions, either way)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need a new rendering system when you restart a world. rendering fails to init correctly when its already been constructed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my information: Why do we need a new rendering system when restarting a world?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its all module drive there really isn't a reason to keep it around as a singleton. just means we have to manage the lifecycle at a much higher level. introduces extra book keeping that I would like to avoid. anyways one session might not have the same rendering setup so the entire state of the RenderingModuleRegistry would need to be wiped. just easier to dispose of the whole object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea.. we do this for quite a few loading things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please persist this information in a docstring. Probably the class doc here is a good place to capture this.
unregisterPrefabFormats(assetTypeManager); | ||
assetTypeManager.getAssetTypes().forEach(k -> { | ||
for (ResourceUrn urn : k.getLoadedAssetUrns()) { | ||
if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) { | ||
k.getAsset(urn).ifPresent(Asset::dispose); | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we unregister prefab formats and dispose assets at this point?
Shouldn't this be done when exiting the previous world rather than when entering the next? 🤔
(same for asset disposal below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as #4829 (review) 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we end up loading those classes again on the classpath so the prefabs are not compatible between sessions.
…oad-a-world-second-time
…fix/resolve-issue-when-attempting-to-load-a-world-second-time
this only broke after the tinting was added I'm sure its a couple line fix but I thought it was out of the scope of this change. @jdrueckert I was planning on looking at this separately. I've addressed the changes that @keturn raised about clean up so these changes are good from that standpoint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests out fine now and I don't see anything in the code that worries me. However, I'd like @keturn and / or @skaldarnar to have a final look, too, so I won't approve this yet.
@keturn, @skaldarnar feel free to approve and merge after you've had a look in case you're good with the changes.
engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java
Outdated
Show resolved
Hide resolved
chunkProvider.dispose(); | ||
|
||
assetTypeManager.getAssetTypes().forEach(k -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is k
supposed to mean here? Can we please name it assetType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assetTypeManager.getAssetTypes().forEach(k -> { | |
// dispose all module assets | |
assetTypeManager.getAssetTypes().forEach(k -> { |
engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java
Outdated
Show resolved
Hide resolved
@@ -17,29 +17,23 @@ public Colorc calcColor(int x, int y, int z) { | |||
COLOR_LUT { | |||
@Override | |||
public Colorc calcColor(int x, int y, int z) { | |||
ColorProvider colorProvider = CoreRegistry.get(ColorProvider.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is doing this lookup in CoreRegistry
fast? I think @tolziplohu put this optimization on purpose to reduce the necessary lookups in the registry with each lookup of a color... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, but we can't save it as a static variable.
@@ -318,7 +318,6 @@ private BlockFamilyDefinitionData createBaseData(JsonObject jsonObject) { | |||
@Override | |||
public Class<? extends BlockFamily> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | |||
throws JsonParseException { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these changes are unrelated to this PR. Please revert them.
|
||
@Override | ||
public boolean step() { | ||
context.put(RenderingModuleRegistry.class, new RenderingModuleRegistry()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please persist this information in a docstring. Probably the class doc here is a good place to capture this.
…ronmentSwitchHandler.java Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
…ame.java Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
…ame.java Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
…ame.java Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java
Outdated
Show resolved
Hide resolved
chunkProvider.dispose(); | ||
|
||
assetTypeManager.getAssetTypes().forEach(k -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assetTypeManager.getAssetTypes().forEach(k -> { | |
// dispose all module assets | |
assetTypeManager.getAssetTypes().forEach(k -> { |
…ame.java Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
…ame.java Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
…esses/InitialiseRendering.java Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
looks like gestalt loads a whole new environment so any assets from one session are not compatible for another session. there are two main things I do, I wipe all the prefabs and let the engine re-resolve them when the world loads and unload any assets that are not loaded in by core.