Raised This Month: $ Target: $400
 0% 

Crashes steam dedicated on exit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zerak
Senior Member
Join Date: Feb 2008
Old 02-25-2008 , 16:42   Crashes steam dedicated on exit
Reply With Quote #1

The following code will make a memory error when closing a steam dedicated server and I have no clue why.
There is no error while running the code either

Code:
#include <sourcemod>

public OnPluginStart()
{
    new Handle:value = CreateArray(1)

    // 0,0,1,0,0,1,0
    PushArrayCell(value, 0)
    PushArrayCell(value, 0)
    PushArrayCell(value, 1)
    PushArrayCell(value, 0)
    PushArrayCell(value, 0)
    PushArrayCell(value, 1)
    PushArrayCell(value, 0)
    
    MergeSortMaps(value, 0, GetArraySize(value)-1 )
    CloseHandle(value)
}

/*
    sort maps after its value hence several lists
*/
MergeSortMaps( Handle:valueList, startIndex, endIndex )
{    
    // base case
    if( startIndex == endIndex )
    {
        return
    }
    
    // sort each half
    new startIndex2 = (startIndex + endIndex) / 2
    MergeSortMaps( valueList, startIndex, startIndex2 )
    startIndex2++
    MergeSortMaps( valueList, startIndex2, endIndex)
    
    // merge the two sorted halves
    new tempValue
    
    while( startIndex < startIndex2 && startIndex2 <= endIndex )
    {
        
        if( GetArrayCell(valueList, startIndex) > GetArrayCell(valueList, startIndex2) )
        {            
            tempValue = GetArrayCell(valueList, startIndex2)
            
            RemoveFromArray(valueList, startIndex2)
            ShiftArrayUp(valueList, startIndex)
            SetArrayCell(valueList, startIndex, tempValue)
            
            startIndex2++
        }
        startIndex++
    }
}
zerak is offline
BAILOPAN
Join Date: Jan 2004
Old 02-25-2008 , 17:14   Re: Crashes steam dedicated on exit
Reply With Quote #2

Are you sure that code is causing it?

Out of curiosity why not use SortADTArrayCustom()
__________________
egg
BAILOPAN is offline
zerak
Senior Member
Join Date: Feb 2008
Old 02-25-2008 , 17:22   Re: Crashes steam dedicated on exit
Reply With Quote #3

This is just a demonstration of the issue I am having, dont know how to use SortADTArrayCustom() and also do a similiar swap on another dynamic array.
And besides that I really want to know what i have made incorrect here
Out of curiosity, does it use quicksort ?
zerak is offline
BAILOPAN
Join Date: Jan 2004
Old 02-25-2008 , 17:24   Re: Crashes steam dedicated on exit
Reply With Quote #4

it uses qsort() which is the C runtime library call for generic quicksorting.

It's easy to use, you implement the callback function and return a comparator (1, 0, or -1 based on the comparison of the items).
__________________
egg
BAILOPAN is offline
zerak
Senior Member
Join Date: Feb 2008
Old 02-25-2008 , 17:30   Re: Crashes steam dedicated on exit
Reply With Quote #5

I did try to use it first but it looked like it just bubbled that is nested for -> N^2
Cause it did a lot of comparisions and I am trying to sort two dynamic arrays based on the values of one of these arrays.
zerak is offline
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 21:50.


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