kerou / mt4j

Automatically exported from code.google.com/p/mt4j
GNU General Public License v2.0
0 stars 0 forks source link

Invalid memory access when creating font #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I use a single font throughout my complete project. Therefore I mostly use:

        IFont font = FontManager.getInstance().createFont(pApplet, "fonts/Trebuchet MS.ttf", 
                16,     //Font size
                new MTColor(255,255,255));  //Font color

However, at one place I wanted to use font-size 12. I copied over the code and 
changed 16 to 12. This resulted in a crash with the following console message:

Invalid memory access of location 0x0 rip=0x7fff88ed00b2

Using the latest SVN checkout of the MT4j project, the latest Java binary 
available to OSX and OSX 10.6.6

Original issue reported on code.google.com by michael....@gmail.com on 28 Feb 2011 at 8:38

GoogleCodeExporter commented 9 years ago
More specifically I can tell that LibJogl is responsible for the crash, but 
maybe that's a result from incorrect usage somewhere inside MT4j? Or it is just 
LibJogl.

Original comment by michael....@gmail.com on 1 Mar 2011 at 10:20

GoogleCodeExporter commented 9 years ago
Crash report in attachment.

Original comment by michael....@gmail.com on 2 Mar 2011 at 9:42

Attachments:

GoogleCodeExporter commented 9 years ago
And this is the terminal output:

INFO - Platform: "Mac OS X" -> Version: "10.6.6" -> JVM Bit: "64"
INFO - Platform: "Mac OS X" -> Version: "10.6.6" -> JVM Bit: "64"
INFO - MT4j window dimensions: "1920 X 1200"
INFO - Maximum framerate: "60"
INFO - OpenGL Version: "2.1 NVIDIA-1.6.26" - Vendor: "NVIDIA Corporation" - 
Renderer: "NVIDIA GeForce GT 130 OpenGL Engine"
INFO - Non power of two texture sizes allowed: "true"
INFO - OpenGL Framebuffer Object Extension available: "true"
INFO - Vertical Sync enabled: "true"
INFO - OpenGL multi-sampling enabled.
INFO - Initializing TUIO input on port: 3333
INFO - Loading new font "fonts/Trebuchet MS.ttf" with factory: 
org.mt4j.components.visibleComponents.font.fontFactories.TTFontFactory
INFO - Loading new font "SansSerif" with factory: 
org.mt4j.components.visibleComponents.font.fontFactories.BitmapFontFactory
Invalid memory access of location 0x0 rip=0x7fff88ecf2c8

Original comment by michael....@gmail.com on 2 Mar 2011 at 9:47

GoogleCodeExporter commented 9 years ago
The one from the crash report happens at the creation of the MTTextArea where a 
default font is created, called SansSerif. If I give the first font created as 
a parameter to the constructor the crash does not happen.

Original comment by michael....@gmail.com on 2 Mar 2011 at 9:51

GoogleCodeExporter commented 9 years ago
Judging from the crash report I think I know what the problem is. You seem to 
create OpenGL resources (textures for the bitmap default font) in another 
thread, which is not the OpenGL thread (main mt4j thread). 
OpenGL is not designed for multithreaded usage, so OpenGL funcitonalitly should 
only be accessed in the thread where the OpenGL context is current. Else, 
errors like this can happen which often dont give the right hint to where the 
problem really lies..
So the solution would be to create the font in the main thread. 
Also useful if using different threads is to use the 
MTApplication.invokeLater(Runnable runnable) method to schedule a piece of code 
to run in the main thread on the start of the next frame.
See also:
http://mt4j.org/mediawiki/index.php/FAQ#How_to_avoid_threading_problems_.3F

Original comment by sirhc.f...@gmail.com on 2 Mar 2011 at 10:02

GoogleCodeExporter commented 9 years ago
Thanks for the rapid response. I already suspected threading as it only started 
when I introduced an extra thread for the retrieval of books. Apparently the 
observer pattern in java uses the same thread as the notifyObservers is invoked 
in and this would indeed result in the problem mentioned above.

Original comment by michael....@gmail.com on 2 Mar 2011 at 10:05

GoogleCodeExporter commented 9 years ago

Original comment by sirhc.f...@gmail.com on 2 Mar 2011 at 10:34