作爲一項練習,我創建了一個小型HTTP服務器,可以生成隨機遊戲機制,類似於this one。我將它寫在Windows 7(32位)系統上,並且工作完美無瑕。但是,當我在我的家用機器Windows 7(64位)上運行它時,它總是失敗,並顯示相同的消息:exit status -1073741819
。我還沒有設法找到引用該狀態碼的任何內容,所以我不知道它有多重要。什麼導致我的HTTP服務器失敗,並顯示「退出狀態-1073741819」?
下面是服務器代碼,具有冗餘刪節:
package main
import (
"fmt"
"math/rand"
"time"
"net/http"
"html/template"
)
// Info about a game mechanic
type MechanicInfo struct { Name, Desc string }
// Print a mechanic as a string
func (m MechanicInfo) String() string {
return fmt.Sprintf("%s: %s", m.Name, m.Desc)
}
// A possible game mechanic
var (
UnkillableObjects = &MechanicInfo{"Avoiding Unkillable Objects",
"There are objects that the player cannot touch. These are different from normal enemies because they cannot be destroyed or moved."}
//...
Race = &MechanicInfo{"Race",
"The player must reach a place before the opponent does. Like \"Timed\" except the enemy as a \"timer\" can be slowed down by the player's actions, or there may be multiple enemies being raced against."}
)
// Slice containing all game mechanics
var GameMechanics []*MechanicInfo
// Pseudorandom number generator
var prng *rand.Rand
// Get a random mechanic
func RandMechanic() *MechanicInfo {
i := prng.Intn(len(GameMechanics))
return GameMechanics[i]
}
// Initialize the package
func init() {
prng = rand.New(rand.NewSource(time.Now().Unix()))
GameMechanics = make([]*MechanicInfo, 34)
GameMechanics[0] = UnkillableObjects
//...
GameMechanics[33] = Race
}
// serving
var index = template.Must(template.ParseFiles(
"templates/_base.html",
"templates/index.html",
))
func randMechHandler(w http.ResponseWriter, req *http.Request) {
mechanics := [3]*MechanicInfo{RandMechanic(), RandMechanic(), RandMechanic()}
if err := index.Execute(w, mechanics); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func main() {
http.HandleFunc("/", randMechHandler)
if err := http.ListenAndServe(":80", nil); err != nil {
panic(err)
}
}
此外,unabridged code的_base.html template和index.html template。
什麼可能導致此問題?是否有像這樣調試隱藏退出狀態的過程?
這是一個訪問衝突0000005的Windows代碼。我搜索了一下,發現了一些關於反病毒軟件和蠕蟲的抱怨。但是,您在32位和64位機器上提到了不同的行爲。您是否正在使用任何可能爲一個架構設計的二進制文件? –
@RayToal不,我只使用了系統上編譯的每個二進制文件。運行編譯後的二進制文件時,我沒有收到退出狀態消息,但它以相同的方式失敗;我想這是因爲Windows的命令提示符沒有顯示退出狀態。當我使用'go run mechanics.go'時,go工具顯示退出狀態。編輯:我也嘗試禁用我的殺毒軟件,但我得到同樣的問題。 – Keeblebrox