Skip to content

Commit 16a28cc

Browse files
Update libjglios (#2813)
* update to new libjglios * Update jme3-ios/src/main/java/com/jme3/asset/plugins/IosBundleLocator.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 1a32b66 commit 16a28cc

4 files changed

Lines changed: 136 additions & 4 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ checkstyle = "13.3.0"
66
jacoco = "0.8.12"
77
lwjgl3 = "3.4.1"
88
angle = "2026-05-09"
9-
libjglios = "0.3"
9+
libjglios = "0.4"
1010
saferalloc = "0.0.8"
1111
nifty = "1.4.3"
1212
spotbugs = "4.9.8"

jme3-ios-examples/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,13 @@ def generateIosNativeImageMetadata = tasks.register('generateIosNativeImageMetad
280280
}
281281
}
282282

283-
libJGLIOS {
283+
iOS {
284284
mainClass = iosChooserLauncherClass
285285
bundleId = 'org.jmonkeyengine.jme3iosexamples'
286286
appName = 'JmeIosExamples'
287287
simulatorDevice = (findProperty('iosSimulatorDevice') ?: 'iPhone 16').toString()
288+
appIcon = file('../jme3-android-examples/src/main/res/mipmap-xxxhdpi/mipmap_monkey.png')
289+
assets.from '../jme3-testdata/src/main/resources', '../jme3-examples/src/main/resources'
288290
}
289291

290292
sourceSets {
@@ -294,8 +296,6 @@ sourceSets {
294296
resources {
295297
srcDir iosNativeImageMetadataDir
296298
srcDir generatedExamplesTestChooserResourcesDir
297-
srcDir '../jme3-testdata/src/main/resources'
298-
srcDir '../jme3-examples/src/main/resources'
299299
}
300300
}
301301
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2009-2026 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.asset.plugins;
33+
34+
import com.jme3.asset.AssetInfo;
35+
import com.jme3.asset.AssetKey;
36+
import com.jme3.asset.AssetLoadException;
37+
import com.jme3.asset.AssetLocator;
38+
import com.jme3.asset.AssetManager;
39+
import org.ngengine.libjglios.core.LibJGLIOSBundleBridge;
40+
41+
import java.io.File;
42+
import java.io.FileInputStream;
43+
import java.io.FileNotFoundException;
44+
import java.io.IOException;
45+
import java.io.InputStream;
46+
47+
/**
48+
* Locates assets inside the iOS application bundle resource directory.
49+
*/
50+
public class IosBundleLocator implements AssetLocator {
51+
52+
private File root;
53+
54+
@Override
55+
public void setRootPath(String rootPath) {
56+
String resourcePath = LibJGLIOSBundleBridge.resourcePath();
57+
if (resourcePath == null || resourcePath.isEmpty()) {
58+
throw new AssetLoadException("Unable to resolve iOS bundle resource path");
59+
}
60+
61+
String relativeRoot = normalizeRootPath(rootPath);
62+
try {
63+
root = new File(resourcePath, relativeRoot).getCanonicalFile();
64+
if (!root.isDirectory()) {
65+
throw new IllegalArgumentException("Given iOS bundle root path \"" + root + "\" is not a directory");
66+
}
67+
} catch (IOException ex) {
68+
throw new AssetLoadException("iOS bundle root path is invalid", ex);
69+
}
70+
}
71+
72+
private static String normalizeRootPath(String rootPath) {
73+
if (rootPath == null || rootPath.isEmpty() || rootPath.equals("/") || rootPath.equals(".")) {
74+
return "";
75+
}
76+
77+
String normalized = rootPath.replace('\\', '/');
78+
while (normalized.startsWith("/")) {
79+
normalized = normalized.substring(1);
80+
}
81+
return normalized;
82+
}
83+
84+
@Override
85+
public AssetInfo locate(AssetManager manager, AssetKey key) {
86+
String name = key.getName();
87+
if (name.startsWith("/")) {
88+
name = name.substring(1);
89+
}
90+
91+
File file = new File(root, name);
92+
if (!file.exists() || !file.isFile()) {
93+
return null;
94+
}
95+
96+
try {
97+
File canonicalFile = file.getCanonicalFile();
98+
if (!isInsideRoot(canonicalFile)) {
99+
return null;
100+
}
101+
return new BundleAssetInfo(manager, key, canonicalFile);
102+
} catch (IOException ex) {
103+
throw new AssetLoadException("Failed to resolve iOS bundle asset path " + file, ex);
104+
}
105+
}
106+
107+
private boolean isInsideRoot(File file) {
108+
String rootPath = root.getPath();
109+
String filePath = file.getPath();
110+
return filePath.equals(rootPath) || filePath.startsWith(rootPath + File.separator);
111+
}
112+
113+
private static final class BundleAssetInfo extends AssetInfo {
114+
115+
private final File file;
116+
117+
private BundleAssetInfo(AssetManager manager, AssetKey key, File file) {
118+
super(manager, key);
119+
this.file = file;
120+
}
121+
122+
@Override
123+
public InputStream openStream() {
124+
try {
125+
return new FileInputStream(file);
126+
} catch (FileNotFoundException ex) {
127+
throw new AssetLoadException("Failed to open iOS bundle asset: " + file, ex);
128+
}
129+
}
130+
}
131+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
INCLUDE com/jme3/asset/General.cfg
22

33
# IOS specific loaders
4+
LOCATOR / com.jme3.asset.plugins.IosBundleLocator

0 commit comments

Comments
 (0)