1

This question is a follow-up to my SO Answer about using Mesa opengl32.dll when a Golang app does not have a graphics driver to launch Fyne Windows.

I'm trying to centralize my code so that it works on any computer (Mac, Windows, Linux). Sometimes the computer already has a compatible driver and does not need the Mesa DLL to present a Fyne window, for example my MacBook runs the code great with no need for Mesa or the env variables below. However on other devices such as my Windows server I found that I need the Mesa DLL with the environment variables set inside the run.bat file.

Right now to run my code on the Windows server I have to use a run.bat file with the following content:

@echo off set GALLIUM_DRIVER=llvmpipe Main.exe pause 

Instead of having this extra bat file that I have to use. I am trying to add these os env variables directly from the main function but it is not working. At the start of the main function I have:

func main() { if !isOpenGLAvailable() { os.Setenv("GALLIUM_DRIVER", "llvmpipe") } // More code } func isOpenGLAvailable() bool { if err := gl.Init(); err != nil { return false } return true } 

How come running the bat file with these env variables works, but adding the env variables from the main function doesn't? Also is there a better way to dynamically check if the Mesa DLL is needed along with these OS env vars?

9
  • 2
    My first guess is that the required DLLs are loaded before your main function. Setting the envs afterwards doesnt automatically load them Commented Mar 20 at 7:12
  • 2
    I'm with Raildex: if the call gl.Init() loads the necessary DLLs, then obviously by the time the call fails, the DLLs are already loaded so it's pointless to set the env. variables they are supposed to inspect. Commented Mar 20 at 8:10
  • @Raildex okay well how do I fix this issue? Any recommendations? Commented Mar 20 at 19:47
  • @kostix do you have any idea of what I can do? Commented Mar 25 at 6:28
  • [1/2] @AhmedZaidan, sorry but I have no simple idea. A complicated one is actually simple to explain but ostensibly hard to implement. Presently you appear to check wheher OpenGL is available by trying to initialize it, and this process "pulls in" some dynamic libraries—initializing them in the process. Consequently, when you later want to re-initialize OpenGL, this fails because even though you set up some env. vars, an attempt to reinitialize OpenGL is effectively becomes a no-op because the necessary libs are already loaded by that time. So what you can do about this? … Commented Apr 2 at 14:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.