Skip to content

Commit

Permalink
Fix[profile_editor]: avoid crash when returning to the editor after l…
Browse files Browse the repository at this point in the history
…eaving Pojav in the background.
  • Loading branch information
artdeell committed Oct 13, 2024
1 parent cbaebec commit 6474015
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,18 @@ private void loadValues(@NonNull String profile, @NonNull Context context){
private MinecraftProfile getProfile(@NonNull String profile){
MinecraftProfile minecraftProfile;
if(getArguments() == null) {
minecraftProfile = new MinecraftProfile(LauncherProfiles.mainProfileJson.profiles.get(profile));
// EDGE CASE: User leaves Pojav in background. Pojav gets terminated in the background.
// Current selected fragment and its arguments are saved.
// User returns to Pojav. Android restarts process and reinitializes fragment without
// going to the main screen. mainProfileJson and profiles left uninitialized, which
// results in a crash.
// Reload the profiles to avoid this edge case.
LauncherProfiles.load();
MinecraftProfile originalProfile = LauncherProfiles.mainProfileJson.profiles.get(profile);
// EDGE CASE: User edits the JSON, so the profile that was edited no longer exists.
// Create a brand new profile as a fallback for this case.
if(originalProfile != null) minecraftProfile = new MinecraftProfile(originalProfile);
else minecraftProfile = MinecraftProfile.createTemplate();
mProfileKey = profile;
}else{
minecraftProfile = MinecraftProfile.createTemplate();
Expand Down

0 comments on commit 6474015

Please sign in to comment.