I have a problem with my custom gamemode:
Sometimes when a menu gets opened, the game freezes and afterwards outputs this in server console (the player always differs of course):
[CODE]
[GermanCooky|85|STEAM_0:1:92547832] Lua Error:
[ERROR]
[/CODE]
I thought it is because I was using net.Receive() inside of a function and moved it outside.
It seemed to work at first, but the error still occurs.
The menu that gets opened is a custom PANEL, here is the code:
[CODE]
local SWRPFrame = {}
function SWRPFrame:Init()
local frame = self
self:SetPos(0, 0)
self:SetSize(ScrW(), ScrH())
self:SetDraggable(false)
self:ShowCloseButton(false)
self:SetTitle("")
self.title = "Star Wars Roleplay"
self.subTitle = "Untertitel"
self.closeButton = true
self.subTitleEnabled = true
--background steht über SWRPFrame:Paint. CloseButton fixen!
self.background = vgui.Create("DImage", self)
self.background:SetPos(0, 0)
self.background:SetSize(self:GetSize())
local oldPaint = self.background.Paint
function self.background:Paint(width, height)
oldPaint(self, width, height)
draw.RoundedBox(0, width * 0.2, 0, width * 0.6, height * 0.1, SWRP:GetColor("grey", 250))
surface.SetDrawColor(SWRP:GetColor("grey", 250))
draw.NoTexture()
surface.DrawPoly({
{x = width * 0.15, y = 0},
{x = width * 0.2, y = 0},
{x = width * 0.2, y = height * 0.1}
})
surface.DrawPoly({
{x = width * 0.8, y = 0},
{x = width * 0.85, y = 0},
{x = width * 0.8, y = height * 0.1}
})
draw.DrawText(string.lower(frame.title), "SWRPTitle", width / 2, 0, SWRP:GetColor("yellow"), TEXT_ALIGN_CENTER)
--subtitle
if frame.subTitleEnabled then
draw.RoundedBox(10, width * 0.25, height * 0.104, width * 0.5, height * 0.08, SWRP:GetColor("grey", 250))
draw.SimpleText(string.lower(frame.subTitle), "SWRPSubTitle", width / 2, height * 0.125, SWRP:GetColor("blue"), TEXT_ALIGN_CENTER)
end
end
self.close = vgui.Create("SWRPCloseButton", self)
self.close:SetPos(self:GetWide() * 0.965, self:GetTall() * 0.01)
self.close:SetSize(self:GetWide() * 0.03, self:GetTall() * 0.05)
self.close:SetPanel(self)
function self.close:Think()
self:SetActivated(frame.closeButton)
end
end
function SWRPFrame:Paint(width, height)
--black background (if the background image is not available)
draw.RoundedBox(0, 0, 0, width, height, SWRP:GetColor("black"))
end
function SWRPFrame:SetTitle(text)
self.title = text
end
function SWRPFrame:SetSubTitle(text)
self.subTitle = text
end
function SWRPFrame:CloseButton(bool)
self.closeButton = bool
end
function SWRPFrame:SetBackground(image)
if file.Exists(image, "GAME") then
self.background:SetImage(image)
end
end
function SWRPFrame:SubTitleEnabled(bool)
self.subTitleEnabled = bool
end
vgui.Register("SWRPFrame", SWRPFrame, "DFrame")
[/CODE]
and here is how I open the panel:
[CODE]
function SWRP:OpenPlayersMenu()
if IsValid(SWRP.PlayersMenu.Frame) then
SWRP.PlayersMenu.Frame:Close()
end
SWRP.PlayersMenu.Frame = vgui.Create("SWRPFrame")
SWRP.PlayersMenu.Frame:SetBackground(SWRP.Config.PlayersMenuBackground)
SWRP.PlayersMenu.Frame:SetSubTitle("Spieler Übersicht")
--rest of the menu here
end
[/CODE]
I hope somebody has a hint on what can cause this issue, because I want to release a server running this gamemode tomorrow.
[editline]10th July 2016[/editline]
Addons that are installed on the server currently:
- FProfiler ([url]https://facepunch.com/showthread.php?t=1517058[/url])
- GMaps ([url]https://scriptfodder.com/scripts/view/2375/gmaps[/url])
- ULX and ULib
- Advanced Duplicator
- some weapons, mostly scripted by myself, but I don't think that they can cause the issue, because it occurs only sometimes when you open a menu.
It seems like the error was fixed by removing FProfiler. I will leave this open until tomorrow, to see whether this issue really got solved.
[editline]10th July 2016[/editline]
Well it is not solved... This time the game not just froze, but instead gave me an engine error: Lua Panic! Something went horribly wrong! "not enough memory"
[editline]10th July 2016[/editline]
Is there anything in the code above that can freeze/crash the game?
[editline]10th July 2016[/editline]
Or at least a way to get a helpfull error / crash dump?
Shouldn't oldPaint(self, width, height) be oldPaint(self.background, width, height)?
self is equal to SWRPFrame.background in this context.
self.background would be equal to SWRPFrame.background.background which would be nil.
If you are getting crashes, post crash logs.
Otherwise, dissect your code, remove parts until it stops crashing.
[QUOTE=Robotboy655;50687792]If you are getting crashes, post crash logs.
Otherwise, dissect your code, remove parts until it stops crashing.[/QUOTE]
That's the Problem: If the game crashes because of this, no Crash Log is generated and the console error just contains nothing.
[CODE]
local oldPaint = self.background.Paint -- This variable doesn't copy the original paint function, it IS the original
function self.background:Paint(width, height) -- This overrides self.background.Paint
oldPaint(self, width, height) -- Therefore, this is calling itself
[/CODE]
I think this is creating an infinite loop. Try using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/PANEL/PaintOver]PANEL:PaintOver[/url] instead.
[QUOTE=MPan1;50689602][CODE]
local oldPaint = self.background.Paint -- This variable doesn't copy the original paint function, it IS the original
function self.background:Paint(width, height) -- This overrides self.background.Paint
oldPaint(self, width, height) -- Therefore, this is calling itself
[/CODE]
I think this is creating an infinite loop. Try using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/PANEL/PaintOver]PANEL:PaintOver[/url] instead.[/QUOTE]
This does not fix the issue.
[editline]11th July 2016[/editline]
I noticed that afer the menu freezes, the ram usage is highering about 5mb per second until the game crashes.
Any idea what could cause this? An infinite loop?
[editline]11th July 2016[/editline]
[CODE]
if SERVER then
net.Start("uniquename")
net.WriteString("test")
net.Send(ply)
end)
end
if CLIENT then
net.Receive("uniquename", function()
--some code here
end)
end
[/CODE]
I have a question to the example code above.
When I don't read something in the net receiver that got written in the net Message (like writing a string with net.Write() but not reading it with net.ReadString()), can it cause any issues?
Also when I do net.ReadInt(32) but no int has been written, can this cause any issues, like the int becoming -[hugenumberhere]?
Sorry, you need to Log In to post a reply to this thread.