Facepunch / garrysmod-issues

Garry's Mod issue tracker
147 stars 56 forks source link

Any error occuring in a rendering hook makes Vector.ToScreen return invalid values for the rest of the session. #462

Open Khubajsn opened 11 years ago

Khubajsn commented 11 years ago

http://facepunch.com/showthread.php?t=1306031&p=42130766&viewfull=1#post42130766

garrynewman commented 11 years ago

Which rendering hooks? All of them? Any of them? Does the error go away when the error is fixed? Do you need to restart GMod to fix it?

robotboy655 commented 11 years ago

I assume any of the 3D rendering hooks. Last two questions: No, Yes.

Khubajsn commented 11 years ago

It happened to me yesterday while using HUDPaint / RenderScreenspaceEffects. I tried to reproduce it to bring further information, but failed. Please consider posting in the thread as oubliette might know more.

There's another thread about this problem on Facepunch, but there's not really much new: http://facepunch.com/showthread.php?t=1268425

Khubajsn commented 11 years ago

Occurred to me today once again, in a SWEP:DrawHUD hook.

function SWEP:DrawHUD()
        -- self.Attachments is a table generated in SWEP.Think
        if (not self.Attachments or #self.Attachments == 0) then
            return;
        end;

        if (IsValid(self.AttachmentsEntity)) then
            halo.Add({self.AttachmentsEntity}, Color(100,255,100), 5, 5, 1, true, false);
        end;

        for k, v in pairs(self.Attachments) do
            surface.SetDrawColor(Color(0,255,0));
            local pos = v.data;

            if (type(pos) ~= "Vector") then
                if (v.type == "bone") then -- v.data is a bone index if v.type is bone
                    pos = self.AttachmentsEntity:GetBonePosition(pos);
                elseif (v.type == "attachment") then -- v.data is attachment ID if v.type is attachment
                    pos = self.AttachmentsEntity:GetAttachment(pos).Pos;
                end;
            end;

            local scr = pos:ToScreen();
            PrintTable(scr); print("");

            surface.DrawRect(scr.x - 5, scr.y - 5, 10, 10);
        end;
    end;

While studying the nonsense output, I've noticed there's a pattern - the values do repeat. Take a look yourself. Pick a X/Y coordinate value and Ctrl+F for it. Is there anything I could do better to help resolve this problem?

Neither of the 'changelevel' and 'reload' fix this from happening. I've indeed had to restart the whole game to get rid of the problem.

NathanX-S commented 3 years ago

@robotboy655 Test seems to suggest that this has been fixed since then.

robotboy655 commented 3 years ago

Unlikely it was fixed if it wasn't looked into. Large numbers usually indicative of the 3D point being offscreen. Perhaps the Lua error that occurred somehow changed the WorldToScreenMatrix irreversibly.