Skip to content

Commit

Permalink
this causes bug when running OpenGL profiler
Browse files Browse the repository at this point in the history
golang/go#26504
using build.Import is not reliable ...
TODO: must compile resources into go binary
  • Loading branch information
einthusan committed Jan 11, 2021
1 parent e834e38 commit 3b10541
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 48 deletions.
24 changes: 0 additions & 24 deletions gl21-cube/cube.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package main // import "github.com/go-gl/example/gl21-cube"

import (
"go/build"
"image"
"image/draw"
_ "image/png"
Expand Down Expand Up @@ -206,26 +205,3 @@ func drawScene() {

gl.End()
}

// Set the working directory to the root of Go package, so that its assets can be accessed.
func init() {
dir, err := importPathToDir("github.com/go-gl/example/gl21-cube")
if err != nil {
log.Fatalln("Unable to find Go package in your GOPATH, it's needed to load assets:", err)
}
err = os.Chdir(dir)
if err != nil {
log.Panicln("os.Chdir:", err)
}
}

// importPathToDir resolves the absolute path from importPath.
// There doesn't need to be a valid Go package inside that import path,
// but the directory must exist.
func importPathToDir(importPath string) (string, error) {
p, err := build.Import(importPath, "", build.FindOnly)
if err != nil {
return "", err
}
return p.Dir, nil
}
24 changes: 0 additions & 24 deletions gl41core-cube/cube.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main // import "github.com/go-gl/example/gl41core-cube"

import (
"fmt"
"go/build"
"image"
"image/draw"
_ "image/png"
Expand Down Expand Up @@ -317,26 +316,3 @@ var cubeVertices = []float32{
1.0, 1.0, -1.0, 0.0, 0.0,
1.0, 1.0, 1.0, 0.0, 1.0,
}

// Set the working directory to the root of Go package, so that its assets can be accessed.
func init() {
dir, err := importPathToDir("github.com/go-gl/example/gl41core-cube")
if err != nil {
log.Fatalln("Unable to find Go package in your GOPATH, it's needed to load assets:", err)
}
err = os.Chdir(dir)
if err != nil {
log.Panicln("os.Chdir:", err)
}
}

// importPathToDir resolves the absolute path from importPath.
// There doesn't need to be a valid Go package inside that import path,
// but the directory must exist.
func importPathToDir(importPath string) (string, error) {
p, err := build.Import(importPath, "", build.FindOnly)
if err != nil {
return "", err
}
return p.Dir, nil
}

0 comments on commit 3b10541

Please sign in to comment.