Skip to content
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

Conversation

pollend
Copy link
Member

@pollend pollend commented Jul 25, 2021

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.

@github-actions github-actions bot added the Type: Bug Issues reporting and PRs fixing problems label Jul 25, 2021
Comment on lines 127 to 135
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);
Copy link
Member Author

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 👎

@pollend pollend requested review from keturn and skaldarnar July 25, 2021 15:38
Copy link
Member

@keturn keturn left a 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?


@Override
public boolean step() {
context.put(RenderingModuleRegistry.class, new RenderingModuleRegistry());
Copy link
Member

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)

Copy link
Member Author

@pollend pollend Jul 26, 2021

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.

Copy link
Member

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?

Copy link
Member Author

@pollend pollend Jul 26, 2021

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Copy link
Member Author

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.

Copy link
Member

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.

Comment on lines 126 to 133
unregisterPrefabFormats(assetTypeManager);
assetTypeManager.getAssetTypes().forEach(k -> {
for (ResourceUrn urn : k.getLoadedAssetUrns()) {
if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) {
k.getAsset(urn).ifPresent(Asset::dispose);
}
}
});
Copy link
Member

@jdrueckert jdrueckert Jul 26, 2021

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)

Copy link
Member

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) 🙃

Copy link
Member Author

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.

@jdrueckert
Copy link
Member

Second World Start Bug

@jdrueckert jdrueckert added Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Topic: UI/UX Requests, Issues and Changes related to screens, artwork, sound and overall user experience Category: Crash Requests, Issues and Changes targeting unexpected terminations, segfaults, etc. labels Jul 27, 2021
@jdrueckert jdrueckert added this to the v5.1.0 milestone Jul 27, 2021
@keturn keturn self-requested a review July 27, 2021 22:10
keturn
keturn previously approved these changes Jul 27, 2021
@keturn keturn dismissed their stale review July 27, 2021 22:11

some changes

pollend and others added 2 commits July 27, 2021 15:21
@pollend pollend requested review from keturn and jdrueckert August 3, 2021 02:31
@jdrueckert
Copy link
Member

I tested this out and it definitely is not crashing anymore, neither when loading nor when starting a second or third world! 🎉

However... I saw the following, so I assume we're still not cleaning up everything properly?
image

I was in my LaS workspace (because testing some other things before) and did the following:

  1. Start a new LaS world
  2. Load an older LaS world
  3. Start a new Core Gameplay world

@pollend
Copy link
Member Author

pollend commented Aug 4, 2021

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.

Copy link
Member

@jdrueckert jdrueckert left a 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.

chunkProvider.dispose();

assetTypeManager.getAssetTypes().forEach(k -> {
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assetTypeManager.getAssetTypes().forEach(k -> {
// dispose all module assets
assetTypeManager.getAssetTypes().forEach(k -> {

@@ -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);
Copy link
Member

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... 🤔

Copy link
Member Author

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 {

Copy link
Member

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());
Copy link
Member

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>
pollend and others added 4 commits August 7, 2021 09:10
…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>
@pollend pollend requested a review from skaldarnar August 7, 2021 18:22
chunkProvider.dispose();

assetTypeManager.getAssetTypes().forEach(k -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assetTypeManager.getAssetTypes().forEach(k -> {
// dispose all module assets
assetTypeManager.getAssetTypes().forEach(k -> {

pollend and others added 4 commits August 7, 2021 15:30
…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>
@skaldarnar skaldarnar changed the title bugfix: resolved loading issue when attempting to start a world twice fix: resolve issue when loading a world a second time Aug 8, 2021
@skaldarnar skaldarnar merged commit 050fd8d into develop Aug 8, 2021
@skaldarnar skaldarnar deleted the bugfix/resolve-issue-when-attempting-to-load-a-world-second-time branch August 8, 2021 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Crash Requests, Issues and Changes targeting unexpected terminations, segfaults, etc. Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Topic: UI/UX Requests, Issues and Changes related to screens, artwork, sound and overall user experience Type: Bug Issues reporting and PRs fixing problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants