LWJGL GLFW hangs on native glfwInit call

For the past months I’ve been working on creating my own game engine for personal use in LWJGL using pieces here and there, especially from developer ThinMatrix’s rightfully credited code, to learn as much as I can while building it. Only recently there has been strange behavior happening when I launch the engine from IntelliJ for testing:

  • After about 6-10 individual times I click run, all subsequent runs suddenly take about 60 seconds for the window to appear.

  • Whenever I restart my PC this hanging resets and I have another 6-10 runs before it hangs everytime again.

  • I located the issue to glfwInit, more specifically at the call to the native method:

      @NativeType("int")   public static boolean glfwInit() {       long __functionAddress = Functions.Init;       return invokeI(__functionAddress) != 0; // Right here   } 
  • I also noticed that this issue only started when I attempted to implement text support in my engine using the STBTrueType library. It was perfectly fine before that. I tried removing the TrueType code but it didn’t fix it.

Here’s a list of things I’ve tried:

  • Clearing my temp folder in case a buggy or corrupted file was present.
  • Recompiling and rebuilding the entire LWJGL jars twice.
  • Building glfw.dll from the GLFW sources and replacing the glfw.dll in the native jars with the former.
  • Reinstalling Java and actually upgrading JDK versions (from 13.0.2 to 14.0.2)
  • Switching IDEs even if I suspected it wouldn’t work.
  • Updating my NVIDIA drivers, and reinstalling them.

I’m quite confused as to what it could be, and I’d be more than happy to share code, thread dumps, or debug info if you deem it necessary. Here is the Github repository with the latest, "faulty" code (fault in quotes because I’m not too sure the code is the problem.)

Thank you very much for any guidance.

P.S: Please tell me if this is better asked in StackOverflow instead of here.

How do i make a reference to another game manager? Not game object

I made a reference here but the drop down list in script seems to not contain the variables from another script

 [SerializeField] private gm MainPlatform;  public Transform SidePlatform; private Vector3 NextSpawnSidePlatform; void Start() {     MainPlatform = GameObject.FindWithTag("gameManager").GetComponent<gm>();     NextSpawnSidePlatform.x = 30.5f;     StartCoroutine(SpawnSidePlatform()); } 

Not able to find the constraints option in the Rigidbody component

I am working on a game tutorial right now and I need to freeze constraints for a model prefab. I add a Rigidbody component and I want to freeze rotations on the x and z axes. However, I am not able to find the option in the component. Is there another way to access rotation constraints (I do not want to code the constraints at the moment)? Or is there something I am missing in the new version. Please do let me know. Thanks

Rigidbody component. It does not have the constraints option here at all!

I am using Unity 5.6.7f1 Personal

Ray-Box (AABB) is slower than without

at the moment im trying my best to write my own raytracer (and its quite fun actually). So the last days I tried implementing a bounding box algorithm to it. But im getting a much slower framerate with the bounding boxes turned on :(. I think it has something to do with checking the box with every ray but I dont know how I could change that. Here is my code:

the Intersection algorythm

bool Intersect(Ray r, float3 lb, float3 rt) {     float3 dir_inv = 1 / r.direction;          double t1 = (lb[0] - r.origin[0]) * dir_inv[0];     double t2 = (rt[0] - r.origin[0]) * dir_inv[0];      double tmin = min(t1, t2);     double tmax = max(t1, t2);      for (int i = 1; i < 3; ++i)     {         t1 = (lb[i] - r.origin[i]) * dir_inv[i];         t2 = (rt[i] - r.origin[i]) * dir_inv[i];          tmin = max(tmin, min(t1, t2));         tmax = min(tmax, max(t1, t2));     }      return tmax > max(tmin, 0.0); } 

My trace function:

RayHit Trace(Ray ray) {     RayHit bestHit = CreateRayHit();     uint count, stride, i;      // Trace ground plane     IntersectGroundPlane(ray, bestHit);      // Trace spheres     _Spheres.GetDimensions(count, stride);     for (i = 0; i < count; i++)     {         if (Intersect(ray, _Spheres[i].position - (_Spheres[i].radius), _Spheres[i].position + (_Spheres[i].radius)))             IntersectSphere(ray, bestHit, _Spheres[i]);     }          // Trace mesh objects     _MeshObjects.GetDimensions(count, stride);     for (i = 0; i < count; i++)     {         //if (Intersect(ray, float3(0.0f, 0.0f, 0.0f), float3(10.0f, 10.0f, 10.0f)))             //IntersectMeshObject(ray, bestHit, _MeshObjects[i]);     }      return bestHit; } 

thanks in advance

Libgdx – TextButtons added to Table – clicklistener not working [closed]

I am having issues trying to implement a menu in a previously created game. I am pretty new to Libgdx and not sure how everything works just yet. I am adding a menu to an already created game scene using a table and text buttons.

My goal:

  1. Click button which shows table full of buttons
  2. Click specific table button and do something with them
  3. Click away from the table area then table/buttons will disappear

I’ve got it all working except connecting the buttons to clicklisteners. I can only think of the buttons not actually being on the top surface where you can click them.

Section of code: Shortened for brevity; class implements InputProcessor

    protected MenuComponent(GameContext context, SeaBattleScene owner) {         super(context, owner);         this.context = context;     }      @Override     public void create() {         batch = new SpriteBatch();         this.stage = new Stage();         Gdx.input.setInputProcessor(stage);         menuUp = new Texture("assets/ui/disengage.png");         menuDown = new Texture("assets/ui/disengagePressed.png");         menuWindow = createMenuWindow();         menuWindow.setVisible(false);         stage.addActor(menuWindow);         stage.getRoot().setPosition(65,150);     }      @Override     public void update() {     }      @Override     public void render() {         batch.begin();         batch.draw((menuButtonIsDown)?menuDown:menuUp, MENU_buttonX, MENU_buttonY);         batch.end();         stage.act();         stage.draw();     }     private Table createMenuWindow() {         //Table View         Table table = new Table();         table.setPosition(675,160);         //Button View         SpriteDrawable upFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         SpriteDrawable downFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         SpriteDrawable checkedFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         TextButtonStyle buttonStyle=new TextButtonStyle(upFormat, downFormat, checkedFormat, new BitmapFont());         //Individual Buttons         TextButton lobbyButton = new TextButton("Back to Lobby",buttonStyle);         lobbyButton.addListener( new ClickListener() {                           public void clicked(InputEvent event, float x, float y) {                 System.out.println("Clicked");             };         });         TextButton mapButton = new TextButton("Show Maps",buttonStyle);         table.add(lobbyButton).pad(3,0,3,0).row();         table.add(mapButton).pad(3,0,3,0).row();         return table;     }           public static Texture createRoundPixMap(Color color, int width,             int height, int cornerRadius) {         Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.Alpha);         pixmap.setBlending(Pixmap.Blending.None);         pixmap.setColor(color.r,color.g,color.b,0.4f);         pixmap.fillCircle(cornerRadius, cornerRadius, cornerRadius);         pixmap.fillCircle(width - cornerRadius, cornerRadius, cornerRadius);         pixmap.fillCircle(width - cornerRadius, height - cornerRadius, cornerRadius);         pixmap.fillCircle(cornerRadius, height - cornerRadius, cornerRadius);         pixmap.fillRectangle(0, cornerRadius, width, height - (cornerRadius * 2));         pixmap.fillRectangle(cornerRadius, 0, width - (cornerRadius * 2), height);         Texture texture = new Texture(pixmap);         pixmap.dispose();         return texture;     } 

Can someone expain or show me what I am doing wrong, so I can fix it to where I can use the buttons?

This is basically what it looks like: Menu

Sending different message on a game level after different amounts of time

So, I am working on an interactive game to aid with anxiety management. In one of the gameplay options, the player has to press buttons for a certain amount of time. Only after the required time has lapsed (with the player holding the buttons down), will the avatar move. So, for example the instruction will be "Press the buttons for 20 seconds to move the player". This part is working. As this is an anxiety game, however, I want to incorporate some breathing activity/instruction into the gameplay. I have chosen to use the 4-7-8 second rule, whereby the player breathes in for 4 seconds, holds their breath for 7 seconds and exhales for 8 seconds. I have no idea how to incorporate something like this into my existent game. Any tips or pointers would be appreciated. I understand that a second timer would be needed, but how would that be able to discern between the 4 seconds, 7 seconds and 8 seconds?

Attached is my existent timer script:

using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement;  public class Timer : MonoBehaviour {     public int timeLeft;     public Text countdownText;     private bool timerStarted;      int start;      public void BeginTimer()     {         StartCoroutine(LoseTime());     }      void Awake()     {         start = timeLeft;     }      public void StopTimer()     {         StopAllCoroutines();         Respawn.Instance.Player2.transform.position = Respawn.Instance.RespawnPoint2.transform.position;         PlayerController.Instance.timerStarted = false;         timeLeft = start;         countdownText.text = "Time Left= " + start;     }      private IEnumerator LoseTime()     {         while (timeLeft > 0)         {             yield return new WaitForSeconds(1);             timeLeft--;             countdownText.text = "Time Left= " + timeLeft;         }                 PlayerController.Instance.Character.GetComponent<Rigidbody2D>().AddForce(PlayerController.Instance.height, ForceMode2D.Impulse);          //SphereController.Instance.Player.GetComponent<Renderer>().material;         print("hi");     }      public void ChangeLevel()     {         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);     } } 

And my playercontroller script:

using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports; using UnityEngine.UI;  public class PlayerController : MonoBehaviour {     public static PlayerController Instance { set; get; }     public float Speed;     public Vector2 height;     public float xMax, xMin, yMin, yMax;     public bool buttonPressed = false;      public Rigidbody2D Character;     public Timer timer;     public Rigidbody2D _rigidbody;      public bool timerStarted = false;      private SerialPort sp = new SerialPort("\\.\COM4", 9600);      Animator anim;     string value;     int button;      private void Awake()     {         FetchReferences();         Instance = this;          //print("hi");          if (AvatarChooser.ava == 1)         {             anim = GameObject.FindWithTag("Player").GetComponent<Animator>();             anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("3");             //print("hi");         }          if (AvatarChooser.ava == 2)         {             anim = GameObject.FindWithTag("Player").GetComponent<Animator>();             anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("1");         }          if (AvatarChooser.ava == 3)         {             anim = GameObject.FindWithTag("Player").GetComponent<Animator>();             anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("2");         }     }      [ContextMenu("FetchReferences")]     private void FetchReferences()     {         if (!Character) Character = GameObject.FindWithTag("Player").GetComponent<Rigidbody2D>();         if (!timer) timer = GameObject.Find("Timer").GetComponent<Timer>();     }      private void Start()     {         if (!sp.IsOpen)         {             sp.Open(); // Open          }         sp.ReadTimeout = 1;          //print(AvatarChooser.ava);     }      private void Update()     {         if (sp.IsOpen)         {             try             {                  value = sp.ReadLine(); //Read the information                 button = int.Parse(value);                  if (button == 9)/*(Input.GetKeyDown(KeyCode.Space))*/  //jump                 {                     buttonPressed = true;                     if (!timerStarted)                     {                          timerStarted = true;                         timer.BeginTimer();                     }                 }                 else                 {                      timer.StopTimer();                 }             }             catch (System.Exception)             {              }         }     }       private void FixedUpdate()     {         Character.position = new Vector3                     (                         Mathf.Clamp(GetComponent<Rigidbody2D>().position.x, xMin, xMax),                         Mathf.Clamp(GetComponent<Rigidbody2D>().position.y, yMin, yMax)                     );     }         void OnDisable()     {         sp.Close();     }  } 

Can I “unmerge” merged meshes UE4?

I set up my character to be modular, by following the UE4 docs.

I used the code at the bottom of the page to implement mesh merging functionality. It does work well, I can merge meshes runtime. I use this to add clothes to my characters.

Just wondering, if there is a way to take off clothes, by unmerging stuff: Something like:

  • store added clothes in a TArray or something
  • then call a function to remove the desired cloth from the array

Of course, I would like to do it at runtime…

Unity 2018.4.25f1 Errors – error CS0118 & error CS0234

I am getting 2 errors in my c# script.

  1. Assets\scripts\playerMovement.cs(8,5): error CS0118: 'PlayerControls' is a namespace but is used like a type
  2. Assets\scripts\playerMovement.cs(4,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)


using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem;  public class playerMovement : MonoBehaviour {     PlayerControls controls;     Vector2 move;     void Awake()     {         controls = new PlayerControls();          controls.Gameplay.move.performed += ctx => move = ctx.ReadValue<Vector2>();         controls.Gameplay.move.canceled += ctx => move = Vector2.zero;     }     void Update()     {         Vector2 m = new Vector2(move.x, move.y) * Time.deltaTime;         transform.Translate(m, Space.World);     } } 

I am using the new Input System 0.2.1 in unity 2018.4.25f.

The PlayerControls script is auto-generated from an Actions Input object, and it is in the main root "Assets".