Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Slick2d] Problem loading a TiledMap in a Applet  (Read 2484 times)
0 Members and 1 Guest are viewing this topic.
Offline Norgas

Junior Newbie





« Posted 2012-06-13 01:25:23 »

Hi everyone!

I'm working on the game using .tmx TiledMap. The standalone version works without a problem. When I try to run my game as an applet, it fails to load the tileset image ( /img/tiles2et.png) of the TiledMap (/map/empty.tmx) :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
Starting real applet
Done loading
Mon Jun 11 18:37:12 EDT 2012 INFO:Starting display 800x600
Mon Jun 11 18:37:12 EDT 2012 INFO:Use Java PNG Loader = true
WARNING: Found unknown Windows version: Windows 7
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
Mon Jun 11 18:37:12 EDT 2012 INFO:Found 3 controllers
Mon Jun 11 18:37:12 EDT 2012 INFO:0 : Logitech USB Headset
Mon Jun 11 18:37:12 EDT 2012 INFO:1 : Logitech USB Keyboard
Mon Jun 11 18:37:12 EDT 2012 INFO:2 : Logitech USB Keyboard
Mon Jun 11 18:37:12 EDT 2012 ERROR:access denied ("java.io.FilePermission" ".\img\..\img\tiles2et.png" "read")
java.security.AccessControlException: access denied ("java.io.FilePermission" ".\img\..\img\tiles2et.png" "read")
   at java.security.AccessControlContext.checkPermission(Unknown Source)
   at java.security.AccessController.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkRead(Unknown Source)
   at java.io.File.exists(Unknown Source)
   at org.newdawn.slick.util.FileSystemLocation.getResourceAsStream(FileSystemLocation.java:52)
   at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:61)
   at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:169)
   at org.newdawn.slick.Image.<init>(Image.java:196)
   at org.newdawn.slick.tiled.TileSet.<init>(TileSet.java:113)
   at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:447)
   at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:122)
   at zis.MapGenerator.generateEmptyMap(MapGenerator.java:34)
   at zis.MapGenerator.<init>(MapGenerator.java:26)
   at zis.PlayState.init(PlayState.java:72)
   at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
   at org.newdawn.slick.AppletGameContainer$Container.initApplet(AppletGameContainer.java:272)
   at org.newdawn.slick.AppletGameContainer$ContainerPanel.initGL(AppletGameContainer.java:229)
   at org.newdawn.slick.AppletGameContainer$ContainerPanel.start(AppletGameContainer.java:216)
   at org.newdawn.slick.AppletGameContainer$1.run(AppletGameContainer.java:92)
Mon Jun 11 18:37:12 EDT 2012 ERROR:Failed to parse tilemap
org.newdawn.slick.SlickException: Failed to parse tilemap
   at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:480)
   at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:122)
   at zis.MapGenerator.generateEmptyMap(MapGenerator.java:34)
   at zis.MapGenerator.<init>(MapGenerator.java:26)
   at zis.PlayState.init(PlayState.java:72)
   at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
   at org.newdawn.slick.AppletGameContainer$Container.initApplet(AppletGameContainer.java:272)
   at org.newdawn.slick.AppletGameContainer$ContainerPanel.initGL(AppletGameContainer.java:229)
   at org.newdawn.slick.AppletGameContainer$ContainerPanel.start(AppletGameContainer.java:216)
   at org.newdawn.slick.AppletGameContainer$1.run(AppletGameContainer.java:92)
Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" ".\img\..\img\tiles2et.png" "read")
   at java.security.AccessControlContext.checkPermission(Unknown Source)
   at java.security.AccessController.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkRead(Unknown Source)
   at java.io.File.exists(Unknown Source)
   at org.newdawn.slick.util.FileSystemLocation.getResourceAsStream(FileSystemLocation.java:52)
   at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:61)
   at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:169)
   at org.newdawn.slick.Image.<init>(Image.java:196)
   at org.newdawn.slick.tiled.TileSet.<init>(TileSet.java:113)
   at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:447)
   ... 9 more


I check multiple time and the two file are in the ZIS.jar. I also try sign my jar and I still get the same result.
I try running loading the map using Stream and I get the same error:

1  
2  
3  
4  
5  
6  
 // Without Stream
map = new TiledMap( "map/empty.tmx", true);
// With Stream
map = new TiledMap(  Thread.currentThread().getContextClassLoader().getResourceAsStream("map/empty.tmx"), "img/");
// or
map = new TiledMap(  Thread.currentThread().getContextClassLoader().getResourceAsStream("map/empty.tmx"));


Applet Demo

Source

Thanks you in advance.
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-06-13 12:26:16 »

Do this: /img/.....
Don't put a '.' at the beginning.

Offline Norgas

Junior Newbie





« Reply #2 - Posted 2012-06-13 20:00:46 »

Thanks you for the reply.

I change the stream line to :
1  
map = new TiledMap(  Thread.currentThread().getContextClassLoader().getResourceAsStream("map/empty.tmx"), "/img/");


And I edit empty.tmx and change the path to the tileset image :
1  
<image source="tiles2et.png" width="200" height="200"/>


I didn't put any '.' in any file and I get this error in the Java console.

Demo applet
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-06-13 22:38:43 »

Why do you have "/img/" there as a parameter. I don't know what the parameters of TiledMap are, but I don't think you should use that. Put the full path in the getResourceAsStream parameter.

Offline Norgas

Junior Newbie





« Reply #4 - Posted 2012-06-14 02:25:29 »

Thanks you again for the quick reply.

What do you mean the full path? "map/empty.tmx" is the full path to the map. The problem seems that slick can't load the tileset image. But empty.tmx seems to have been loaded otherwise the error log won't mention "tiles2et.png".

The second parameter ("/img/") is optional and is only the location which we can find tileset images.
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-06-14 07:52:31 »

Then what is that "./img/tiles2et.png" file? The code you are showing me doesn't show you loading that, unless that is automatically loaded by the TiledMap. If that is so, then remove the "/img/" parameter.

Offline Norgas

Junior Newbie





« Reply #6 - Posted 2012-06-14 19:24:07 »

The TiledMap automatically loads the tileset image. If I remove the "/img/" and I change empty.tmx to:
1  
<image source="/img/tiles2et.png" width="200" height="200"/>


I still get the same error log. I think that the TiledMap doesn't use a stream when loading the tileset image and thus the error.
I found in the Slick2d source the line responsible for loading the tileset image:
1  
 Image image = new Image(tilesLocation+"/"+ref,false,Image.FILTER_NEAREST,trans);


Is it possible to use TiledMap in a applet?

Offline davedes
« Reply #7 - Posted 2012-06-14 23:10:41 »

When you pass a string to a Slick Image/Sound/etc. it will work like so:

- Search the classpath:
1  
...getClassLoader().getResource(cpRef);

- If that fails, search the file system (hence your error).
- If that fails, throw a RuntimeException. (not really the best thing Slick could do...)

So your problem is because Slick can't find the image in the classpath based on the tilesLocation + "/" + ref path.

Ideally TiledMap should allow you to set the image yourself. I am not familiar with TiledMap (liam has been handling changes) so I'd have to look into it a bit before making changes.

You could get rid of the security exception like so:
1  
2  
ResourceLoader.removeAllResourceLocations();
ResourceLoader.addResourceLocation(new ClasspathLocation());

(this won't really fix your problem, since it's clear Slick can't find the file in the classpath...)

Offline Norgas

Junior Newbie





« Reply #8 - Posted 2012-06-14 23:51:32 »

Ok I will create my own map format and use it instead of TiledMap.

Thanks for all the replies!
Offline Sickan

Senior Devvie


Medals: 9



« Reply #9 - Posted 2012-06-15 03:50:35 »

Ok I will create my own map format and use it instead of TiledMap.

Thanks for all the replies!
Mother of God...  Roll Eyes
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #10 - Posted 2012-06-15 04:30:56 »

No need to create your own format. Just look into why Slick can't find the file. Could be as simple as moving it into a folder "img/".

If all else fails, modify the TiledMap source.

Offline Norgas

Junior Newbie





« Reply #11 - Posted 2012-06-16 02:42:24 »

Sorry my english is terrible. I don't mean to said that I want to create a map "format". My game uses procedural generation for the generation of map. I can easily replace TiledMap by a simple multidimensional array_list. The support of TiledMap in a applet is not that important for my game project.
I can still modify TiledMap  like you said and make it use a stream. Maybe that would fix my error.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!