this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

avoid deadlock in openMap if textures missing

Stops freezes on Linux

+48 -25
+48 -25
src/main/java/game/map/editor/MapEditor.java
··· 3699 3699 * 3700 3700 * @param map 3701 3701 */ 3702 - private void loadMapResources(boolean reloadTextures) 3702 + private boolean tryLoadTextures(boolean reloadTextures) 3703 3703 { 3704 - boolean loadedTextures = !reloadTextures; 3705 - if (!loadedTextures) 3706 - loadedTextures = TextureManager.load(map.texName); 3704 + if (!reloadTextures) 3705 + return true; 3706 + return TextureManager.load(map.texName); 3707 + } 3707 3708 3708 - while (!loadedTextures) { 3709 - int choice = SwingUtils.getConfirmDialog() 3710 - .setParent(gui) 3711 - .setTitle("Missing Texture Archive") 3712 - .setMessage("Could not open texture archive \"" + map.texName + "\", select a different one?") 3713 - .setOptionsType(JOptionPane.YES_NO_OPTION) 3714 - .choose(); 3709 + /** 3710 + * Shows dialog to select alternate texture archive. 3711 + * @return the selected texture name, or null if user cancelled 3712 + */ 3713 + private String promptForTextureArchive() 3714 + { 3715 + int choice = SwingUtils.getConfirmDialog() 3716 + .setParent(gui) 3717 + .setTitle("Missing Texture Archive") 3718 + .setMessage("Could not open texture archive \"" + map.texName + "\", select a different one?") 3719 + .setOptionsType(JOptionPane.YES_NO_OPTION) 3720 + .choose(); 3715 3721 3716 - if (choice == JOptionPane.YES_OPTION) { 3717 - File texFile = SelectTexDialog.showPrompt(); 3718 - if (texFile != null) { 3719 - String texName = FilenameUtils.getBaseName(texFile.getName()); 3720 - loadedTextures = TextureManager.load(texName); 3721 - } 3722 + if (choice == JOptionPane.YES_OPTION) { 3723 + File texFile = SelectTexDialog.showPrompt(); 3724 + if (texFile != null) { 3725 + return FilenameUtils.getBaseName(texFile.getName()); 3722 3726 } 3723 - else 3724 - break; 3725 3727 } 3728 + return null; 3729 + } 3726 3730 3731 + private void loadMapResourcesAfterTextures() 3732 + { 3727 3733 TextureManager.assignModelTextures(map); 3728 3734 3729 3735 for (Model mdl : map.modelTree) ··· 3954 3960 if (newMap == null) 3955 3961 return; 3956 3962 3957 - // this MUST run with GLContext available 3963 + final boolean[] texturesLoaded = { false }; 3964 + final boolean[] reloadTexturesFlag = { false }; 3965 + 3966 + // Release old resources and try to load textures 3958 3967 runInContext(() -> { 3959 3968 String prevTexName = (thumbnailMode || map == null) ? null : map.texName; 3960 - boolean reloadTextures = !newMap.texName.equals(prevTexName); 3969 + reloadTexturesFlag[0] = !newMap.texName.equals(prevTexName); 3961 3970 3962 3971 if (map != null) 3963 - releaseMapResources(reloadTextures); 3972 + releaseMapResources(reloadTexturesFlag[0]); 3964 3973 3965 3974 loading = true; 3966 3975 map = newMap; 3967 3976 3968 - loadMapResources(reloadTextures); 3977 + texturesLoaded[0] = tryLoadTextures(reloadTexturesFlag[0]); 3978 + }); 3979 + 3980 + // If textures failed, show dialog (outside runInContext to avoid deadlock) 3981 + while (!texturesLoaded[0]) { 3982 + String altTexName = promptForTextureArchive(); 3983 + if (altTexName == null) 3984 + break; 3985 + 3986 + runInContext(() -> { 3987 + texturesLoaded[0] = TextureManager.load(altTexName); 3988 + }); 3989 + } 3969 3990 3991 + // Rest of map loading 3992 + runInContext(() -> { 3993 + loadMapResourcesAfterTextures(); 3970 3994 loadOverrides(); 3971 3995 3972 3996 updateRecentMaps(); ··· 3983 4007 } 3984 4008 3985 4009 if (!thumbnailMode) { 3986 - final Map guiMap = newMap; 3987 4010 SwingUtilities.invokeLater(() -> { 3988 4011 updateWindowTitle(); 3989 - gui.setMap(guiMap); 4012 + gui.setMap(map); 3990 4013 }); 3991 4014 3992 4015 if (map.editorData != null) {