Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug?] glfwUpdateGamepadMappings cause java.lang.OutOfMemoryError: Out of stack space. #462

Closed
XenoAmess opened this issue Apr 30, 2019 · 1 comment

Comments

@XenoAmess
Copy link

I don't know how it happened, and if it is my own fault or just another bug.

Exception in thread "main" java.lang.OutOfMemoryError: Out of stack space.
at org.lwjgl.system.MemoryStack.nmalloc(MemoryStack.java:315)
at org.lwjgl.system.MemoryStack.nASCII(MemoryStack.java:636)
at org.lwjgl.glfw.GLFW.glfwUpdateGamepadMappings(GLFW.java:4225)
at com.xenoamess.cyan_potion.base.GameWindow.initGlfw(GameWindow.java:126)
at com.xenoamess.cyan_potion.base.GameWindow.init(GameWindow.java:71)
at com.xenoamess.cyan_potion.base.GameManager.initGameWindow(GameManager.java:380)
at com.xenoamess.cyan_potion.base.GameManager.startup(GameManager.java:134)
at com.xenoamess.cyan_potion.cyan_potion_demo.ForceEntrance.main(ForceEntrance.java:15)


  1. I'm sure I run glfwUpdateGamepadMappings after glfwinit.
  2. I simply use this to get the text from gamecontrollerdb.txt

package com.xenoamess.cyan_potion;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

/**
 * @author XenoAmess
 */
public class SDL_GameControllerDB_Util {
    private static String SDL_GameControllerDB = null;

    public static String getSDL_GameControllerDB() {
        if (SDL_GameControllerDB == null) {
            SDL_GameControllerDB = loadFile("/gamecontrollerdb.txt");
        }
        return SDL_GameControllerDB;
    }

    private static URL getURL(String resourceFilePath) {
        final URL res = SDL_GameControllerDB_Util.class.getResource(resourceFilePath);
        return res;
    }

    private static String loadFile(String resourceFilePath) {
        String res = "";
        try (
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(getURL(resourceFilePath).openStream()));
        ) {
            final StringBuffer sb = new StringBuffer();
            String tmp;
            while (true) {
                tmp = bufferedReader.readLine();
                if (tmp == null) {
                    break;
                }
                sb.append(tmp);
                sb.append("\n");
            }
            res = sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res;
    }
}
  1. I am sure the string is loaded, and have value.
  2. If you need the exact source codes of my work for reproducing the bug then I can give you a copy.
@Spasi Spasi added the Type: Bug label May 1, 2019
@Spasi
Copy link
Member

Spasi commented May 1, 2019

Hey @XenoAmess,

LWJGL uses the MemoryStack internally to encode string parameters, but gamecontrollerdb.txt is bigger (162kb) than the default stack size (64kb).

One way to avoid the error is to increase the default stack size with Configuration.STACK_SIZE (or -Dorg.lwjgl.system.stackSize). However, reading the db as a Java string, then serializing it again is wasteful. A better option is to read the file as a ByteBuffer directly and use the glfwUpdateGamepadMappings(ByteBuffer) overload.

I'll also try to make glfwUpdateGamepadMappings(CharSequence) use a heap allocation internally, or maybe remove it completely. Thanks for opening this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants