Raised This Month: $51 Target: $400
 12% 

Loop not breaking, server hanging...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SuperRaWR
SourceMod Donor
Join Date: Jan 2010
Location: Sylvan Lake, Alberta, Ca
Old 01-13-2011 , 13:47   Loop not breaking, server hanging...
Reply With Quote #1

http://ampaste.net/m71064bc0

When I call public Action:Command_sendLocation(client, args), the for loop that loops through the clients doesn't break if there's more than 1 client, and it makes the server hang, clients disconnect, and I'm unable to unload the plugin, I have to restart the server.

I put in a bunch of PrintToServer's, which is how I knew that the loop isn't breaking...

To me, it appears as though I'm looping through the clients correctly, but it's not working, I've stared at this for hours now, and I can't figure it out, and would really appreciate it if someone could take some time and point me in the right direction. I'm new to pawn btw.
__________________
[WDZ]SuperRaWR

I use event scripts.
SuperRaWR is offline
Send a message via Skype™ to SuperRaWR
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-13-2011 , 16:20   Re: Loop not breaking, server hanging...
Reply With Quote #2

The loops seems fine to me.

Maybe it's SocketSend() that hangs because the socket isn't connected ?
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
SuperRaWR
SourceMod Donor
Join Date: Jan 2010
Location: Sylvan Lake, Alberta, Ca
Old 01-13-2011 , 16:39   Re: Loop not breaking, server hanging...
Reply With Quote #3

But it's I had PrintToServer's inside the loop, and they'd keep calling over and over again, so it shouldn't have anything to do with SocketSend(), although you are right, i should have a conditional to ensure we're connected before calling that.
__________________
[WDZ]SuperRaWR

I use event scripts.
SuperRaWR is offline
Send a message via Skype™ to SuperRaWR
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 01-13-2011 , 16:42   Re: Loop not breaking, server hanging...
Reply With Quote #4

good way to save in local file
and read this file from web via php's functions
__________________
Leonardo is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-13-2011 , 17:06   Re: Loop not breaking, server hanging...
Reply With Quote #5

The only other explanations I have is that the var "i" somehow get's altered inside the loop (memory corruption ?) or MaxClients being something insane high.

Use that for debugging:

PHP Code:
PrintToServer("[DEBUG] %d <= %d"iMaxClients); 
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 01-13-2011 , 17:21   Re: Loop not breaking, server hanging...
Reply With Quote #6

btw
PHP Code:
        for (new i=1i<=MaxClientsi++)
        {
                new 
String:tempStr[32]; // line 34
                
if (IsClientInGame(i) && IsPlayerAlive(i) && socketConnected)
                {
                        
decl Float:vecClientEyePos[3];
                        
GetClientEyePosition(ivecClientEyePos);
                        
Format(tempStr128"C:%iX:%fY:%f",i,vecClientEyePos[0],vecClientEyePos[1]);
                        
StrCat(sendBuffersizeof(sendBuffer), tempStr);
                }       
        } 
1/ I guess this is bad to allocate memory on each client (line 34)
2/ tempStr's size 32, but in Format it's a 128.
3/ socketConnected shouldn't be in cycle
4/ (maybe) should add IsClientConnected() in line 35
__________________
Leonardo is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-13-2011 , 17:46   Re: Loop not breaking, server hanging...
Reply With Quote #7

Oh yeah, Gogo Gadgeto Memory Corruption
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
toazron1
Senior Member
Join Date: Oct 2006
Old 01-14-2011 , 02:52   Re: Loop not breaking, server hanging...
Reply With Quote #8

What you want is something like this:

PHP Code:
    new String:tempStr[32], Float:vecClientEyePos[3];
    if (
socketConnected)
    {
        for (new 
i=1i<=MaxClientsi++)
        {
            if (
IsClientInGame(i) && IsPlayerAlive(i))
            {
                
GetClientEyePosition(ivecClientEyePos);
                
Format(tempStrsizeof(tempStr), "C:%iX:%fY:%f"ivecClientEyePos[0], vecClientEyePos[1]);
                
StrCat(sendBuffersizeof(sendBuffer), tempStr);
            }    
        }
        
SocketSend(socketReceivesendBuffer);
        
sendBuffer "";
    } 
Also - IsClientInGame() implies IsClientConnected afaik
__________________
toazron1 is offline
Send a message via AIM to toazron1
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:49.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode