Raised This Month: $ Target: $400
 0% 

Run time error 5: memory access


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
taheri6
Member
Join Date: Mar 2006
Old 01-05-2008 , 17:49   Run time error 5: memory access
Reply With Quote #1

I dont mean to double post, but I also have another problem - I get this error in my amxx error log : "Run time error 5: memory access "

The line it refers to in the error log is just a

Code:
return PLUGIN_CONTINUE
Im not the most experienced coder and Im the first to admit that, but I dont know what this means beyond the obvious - am I trying to access something that doesnt exist, or the task that is calling this is no longer present (remove_task called somewhere too early?) or something else Im missing?
taheri6 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-05-2008 , 17:52   Re: Run time error 5: memory access
Reply With Quote #2

Show the full code, please...
__________________
Arkshine is offline
taheri6
Member
Join Date: Mar 2006
Old 01-05-2008 , 23:05   Re: Run time error 5: memory access
Reply With Quote #3

spacing got a little wierd in the paste, so forgive that.

PHP Code:
//Called during plugin init 
public Initialize_CLCMD ( )
{
   [...
blah...]
    
register_clcmd "wcentangle""Ult_Entangle",    -1"-Entangle Ultimate" );
   [...
blah...]
}

//Ran when client commands
public Ult_Entangle id )
{

    if ( !
Ult_Can_Use idSKILLIDX_ENTANGLE ) )
    {
        return 
PLUGIN_HANDLED;
    }

    if ( 
is_user_alive id ) && is_user_connectedid ) && !issearching[id] && !ultimateused[id] )
    {
        new 
parm[2];
        
parm[0] = id;
        
parm[1] = ULTIMATESEARCHTIME;
        
Task_Search_Event_Entangle parm );
    }

    return 
PLUGIN_CONTINUE;
}

//Client command function calls this and loops through it on occassion until a match is found
//This is where it errors out in the logs
public Task_Search_Event_Entangle parm[2] )
{
    new 
waitparm[6];
    new 
iparm[2];
    new 
id parm[0];
    new 
enemyzbody;
    new 
counter;

    if ( !
is_user_connectedid ) )
    {
        
icon_controller id );
        return 
PLUGIN_CONTINUE;
    }

    
get_user_aiming id,enemyzbody );

    if ( ( 
get_user_team enemyz ) == SPEC ) || !is_user_connectedenemyz ) )
    {
        
icon_controller id );
        return 
PLUGIN_CONTINUE;
    }

    if ( !
p_resists[enemyz][RESISTIDX_MAGIC])
    {
        
p_resists[enemyz][RESISTIDX_MAGIC] = 0;
    }

    if ( ( 
enemyz <= 32 ) && ( p_resists[enemyz][RESISTIDX_MAGIC] >= RESIST_MAX_VALUE ) || ( !temp_immunity[enemyz] && magic_saving_throw enemyz ) ) )
    {
        
temp_immunity[enemyz] = true;

        if ( 
is_user_connectedenemyz ) && !is_user_botenemyz ) )
        {
            
client_print enemyzprint_chat"%L"enemyz"ULTIMATE_ENGANGLE_RESISTANT"MOD );
        }
        
        
iparm[0] = enemyz;
        
formatiparm[1], 31"%s""Entangling roots" );
        
set_task 5.0"Task_Reset_Immunity"TASK_RESET_IMMUNITY idiparm);
    }

    if ( 
0<enemyz<=32 && !stunned[enemyz] && get_user_team id )!=get_user_team enemyz ) && playeritem[enemyz]!=IMMUNITY && !hasblink[enemyz] && is_user_alive id ) && is_user_alive enemyz ) && !temp_immunity[enemyz] )
    {
        
issearching[id] = false;
        
ultimateused[id] = true;
        
icon_controller id );

        if ( 
is_user_connectedenemyz ) && !is_user_botenemyz ) )
        {
            if ( 
file_exists "sound/warcraft3/entanglingrootstarget1.wav" ) == )
            {
                
emit_sound idCHAN_ITEM"warcraft3/entanglingrootstarget1.wav"1.0ATTN_NORM0PITCH_NORM );
            }
            else
            {
                if ( 
file_exists "sound/weapons/cbar_hitbod3.wav" ) == )
                {
                    
emit_sound id,CHAN_ITEM"weapons/cbar_hitbod3.wav"1.0ATTN_NORM0PITCH_NORM );
                }
            }
        }
        
        
waitparm[0] = enemyz;
        
waitparm[1] = 100;
        
waitparm[5] = floatround get_user_maxspeed enemyz ) );
        
set_user_maxspeed enemyz,1.0 );
        
Task_Entangle_Stop waitparm );

        
stunned[enemyz] = true;
        new 
cooldownparm[1];
        
cooldownparm[0] = id;
        
set_task CVAR_ENTANGLE_COOLDOWN"cooldown"50 idcooldownparm);
    }
    else
    {
        
issearching[id] = true;
        
icon_controller id );
        
counter parm[1];

        while ( 
counter >= )
        {
            
counter -= 10;
            if ( 
counter == )
            {
                
emit_sound idCHAN_ITEM"turret/tu_ping.wav"1.0ATTN_NORM0PITCH_NORM );
            }
        }
        --
parm[1];

        if ( 
parm[1]>&& get_user_health id ) > )
        {
            
set_task 0.1"Task_Search_Event_Entangle"TASK_ULTIMATE_ENTANGLE_SEARCH idparm);
        }
        else
        {
            
issearching[id] = false;
            
icon_controller id );
        }
    }

    return 
PLUGIN_CONTINUE;



Last edited by taheri6; 01-06-2008 at 01:55.
taheri6 is offline
taheri6
Member
Join Date: Mar 2006
Old 01-07-2008 , 00:26   Re: Run time error 5: memory access
Reply With Quote #4

Anyone have any ideas?
__________________
http://www.yaur.com -=[Yaur]=- Clan Website
taheri6 is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 01-07-2008 , 08:45   Re: Run time error 5: memory access
Reply With Quote #5

First of all you might wanna clean up your code.

!is_user_connected( enemyz ) is a redundant check as get_user_aiming() returns data only from alive players.
Code:
get_user_aiming ( id,enemyz, body ); 

    if ( ( get_user_team ( enemyz ) == SPEC ) || !is_user_connected( enemyz ) ) 
    { 
        icon_controller ( id ); 
        return PLUGIN_CONTINUE; 
    }
This implies that futher checks to enemyz are also redundant. To test if enemyz hold a valid player id you should add enemyz = 0 before calling get_user_aiming(). Further testing will be done by if( enemyz ).

Also redundant
Code:
if ( !p_resists[enemyz][RESISTIDX_MAGIC]) 
    { 
        p_resists[enemyz][RESISTIDX_MAGIC] = 0; 
    }
I can't see the purpose of the format() call. Please note that iparm is declared as new iparm[2]; - format() goes out of bounds there.
Code:
iparm[0] = enemyz; 
        format( iparm[1], 31, "%s", "Entangling roots" );
This can be changed in regard to what I've said above.
Code:
if ( 0<enemyz<=32 && !stunned[enemyz] && get_user_team ( id )!=get_user_team ( enemyz ) && playeritem[enemyz]!=IMMUNITY && !hasblink[enemyz] && is_user_alive ( id ) && is_user_alive ( enemyz ) && !temp_immunity[enemyz] )
Extra param cooldownparm not needed here as id is part of the taskid. In your task simply do a id = taskid - 50;
Code:
set_task ( CVAR_ENTANGLE_COOLDOWN, "cooldown", 50 + id, cooldownparm, 1 );
If you want to emit_sound() if counter is a multiple of 10 you can do if( !(counter % 10) ). This is redundant
Code:
while ( counter >= 0 ) 
        { 
            counter -= 10; 
            if ( counter == 0 ) 
            { 
                emit_sound ( id, CHAN_ITEM, "turret/tu_ping.wav", 1.0, ATTN_NORM, 0, PITCH_NORM ); 
            } 
        }
Another thig is this
Code:
set_task ( 0.1, "Task_Search_Event_Entangle", TASK_ULTIMATE_ENTANGLE_SEARCH + id, parm, 2 );
but Task_Search_Event_Entangle() is declared as
Code:
public Task_Search_Event_Entangle ( parm[2] )
Your firs call to Task_Search_Event_Entangle() acts like a "normal" function call but the second call requires that Task_Search_Event_Entangle() is a task with extra param. You should add a taskid in the declaration and work your way with that. You can build your taskid same way you did with the "cooldown()" task.



Please review your code as you have lots of redundant tests. While this shouldn't be a problem, in your case it's just a code overhead, not to mention that your task is recursive with a 0.1 seconds delay.

Last edited by _Master_; 01-07-2008 at 09:04.
_Master_ is offline
taheri6
Member
Join Date: Mar 2006
Old 01-07-2008 , 13:41   Re: Run time error 5: memory access
Reply With Quote #6

Would it be better to remove the first call as a function and make that as a set_task instead?

change to

PHP Code:
public Ult_Entangle id 


    if ( !
Ult_Can_Use idSKILLIDX_ENTANGLE ) ) 
    { 
        return 
PLUGIN_HANDLED
    } 

    if ( 
is_user_alive id ) && is_user_connectedid ) && !issearching[id] && !ultimateused[id] ) 
    { 
        new 
parm[2]; 
        
parm[0] = id
        
parm[1] = ULTIMATESEARCHTIME
        
set_task 0.1"Task_Search_Event_Entangle"TASK_ULTIMATE_ENTANGLE_SEARCH idparm);
        
//Task_Search_Event_Entangle ( parm );  //Set_Task instead
    


    return 
PLUGIN_CONTINUE

__________________
http://www.yaur.com -=[Yaur]=- Clan Website

Last edited by taheri6; 01-07-2008 at 13:59.
taheri6 is offline
taheri6
Member
Join Date: Mar 2006
Old 01-11-2008 , 01:07   Re: Run time error 5: memory access
Reply With Quote #7

ok so I have tried some of what was above and the error still persists. Even though some of the code is redundant and not "optimized" I would like to get it working before I worry about the optimization portion.

I have also set the function as a task instead of a direct call, and removed the delcared parm[2] from the function params.

Here is what I got now - I know there are still some redundancies, but thats ok for now. I would like to focus on what is completely wrong. I'm trying to port in some existing code from the original uwc3 mod plugin and this is the only part that is giving me trouble.

PHP Code:
public Ult_Entangle id )  
{  

    if ( !
Ult_Can_Use idSKILLIDX_ENTANGLE ) )  
    {  
        return 
PLUGIN_HANDLED;  
    }  

    if ( 
is_user_alive id ) && Util_Is_Valid_Playerid ) && !issearching[id] && !ultimateused[id] )  
    {  
        new 
parm[2];  
        
parm[0] = id;  
        
parm[1] = ULTIMATESEARCHTIME;  
        
set_task 0.1"Task_Search_Event_Entangle"TASK_ULTIMATE_ENTANGLE_SEARCH idparm); 
        
//Task_Search_Event_Entangle ( parm );  //Set_Task instead 
    
}  

    return 
PLUGIN_CONTINUE;  


PHP Code:
public Task_Search_Event_Entangle parm[] )
{
    new 
iparm[2], waitparm[6];
    new 
enemyzbodycounter;
    new 
tmp_immunity 0id parm[0];

    if ( !
Util_Is_Valid_Playerid ) )
    {
        
issearching[id] = true;
        
icon_controller id );
        return 
PLUGIN_CONTINUE;
    }

    
get_user_aiming idenemyzbody );

    if ( !
Util_Is_Valid_Playerenemyz ) )
    {
        
issearching[id] = true;
        
icon_controller id );
        return 
PLUGIN_CONTINUE;
    }

    if( 
temp_immunity[enemyz] || playeritem[enemyz]==IMMUNITY || hasblink[enemyz] )
    {
        
tmp_immunity 1;
    }

    if ( 
Util_NotSame_Teamidenemyz ) && ( tmp_immunity || magic_saving_throw enemyz ) ) )
    {
        
temp_immunity[enemyz] = true;
        
tmp_immunity 1;

        if ( 
Util_Should_Msg_Clientenemyz ) )
        {
            
client_print enemyzprint_chat"%L"enemyz"ULTIMATE_ENGANGLE_RESISTANT"MOD );
        }
        
        
iparm[0] = enemyz;
        
copyiparm[1], 31"Entangling roots" );
        
set_task 5.0"Task_Reset_Immunity"TASK_RESET_IMMUNITY idiparm);
    }

    if ( !
stunned[enemyz] && Util_NotSame_Teamidenemyz ) && !tmp_immunity )
    {
        
issearching[id] = false;
        
ultimateused[id] = true;
        
icon_controller id );

        if ( 
Util_Should_Msg_Clientid ) )
        {
            if ( 
file_exists "sound/warcraft3/entanglingrootstarget1.wav" ) == )
            {
                
emit_sound idCHAN_ITEM"warcraft3/entanglingrootstarget1.wav"1.0ATTN_NORM0PITCH_NORM );
            }
            else
            {
                if ( 
file_exists "sound/weapons/cbar_hitbod3.wav" ) == )
                {
                    
emit_sound id,CHAN_ITEM"weapons/cbar_hitbod3.wav"1.0ATTN_NORM0PITCH_NORM );
                }
            }
        }
        
        
waitparm[0] = enemyz;
        
waitparm[1] = 100;
        
waitparm[5] = floatround get_user_maxspeed enemyz ) );
        
set_user_maxspeed enemyz,1.0 );
        
Task_Entangle_Stop waitparm );

        
stunned[enemyz] = true;
        new 
cooldownparm[1];
        
cooldownparm[0] = id;
        
set_task CVAR_ENTANGLE_COOLDOWN"cooldown"50 idcooldownparm);
    }
    else
    {
        
issearching[id] = true;
        
icon_controller id );
        
counter parm[1];

        while ( 
counter >= )
        {
            
counter -= 10;
            if ( 
counter == )
            {
                if( 
Util_Should_Msg_Clientid ) )
                {
                    
emit_sound idCHAN_ITEM"turret/tu_ping.wav"1.0ATTN_NORM0PITCH_NORM );
                }
            }
        }
        --
parm[1];

        if ( 
parm[1]>&& get_user_health id ) > )
        {
            
set_task 0.1"Task_Search_Event_Entangle"TASK_ULTIMATE_ENTANGLE_SEARCH idparm);
        }
        else
        {
            
issearching[id] = false;
            
icon_controller id );
        }
    }

    return 
PLUGIN_CONTINUE
PHP Code:
public Util_Is_Valid_Playerid )
{
    if( 
== id || id MAX_PLAYERS )
    {
        return 
false;
    }

    if( 
is_user_connectedid ) && ( pevidpev_flags ) & FL_CLIENT ) )
    {
        return 
true;
    }

    return 
false;
}

public 
Util_Should_Msg_Clientid )
    {
    if( 
Util_Is_Valid_Player(id) && !is_user_botid ) )
    {
        return 
true;
    }

    return 
false;
}

public 
Util_IsSame_Team PlayerIDTargetID )
{
    new 
bool:IsValidTeam false;

    if ( 
get_user_team PlayerID ) == get_user_team TargetID ) && !Util_Player_Is_Spec PlayerID ) && !Util_Player_Is_Spec TargetID ) )
    {
        
IsValidTeam true;
    }
    
    return 
IsValidTeam;
}

public 
Util_NotSame_Team PlayerIDTargetID )
{
    new 
bool:IsValidTeam false;

    if ( 
get_user_team PlayerID ) != get_user_team TargetID ) && !Util_Player_Is_Spec PlayerID ) && !Util_Player_Is_Spec TargetID ) )
    {
        
IsValidTeam true;
    }
    
    return 
IsValidTeam;

Maybe I just need another set of eyes..... Thanks in advance.
__________________
http://www.yaur.com -=[Yaur]=- Clan Website
taheri6 is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 01-11-2008 , 10:45   Re: Run time error 5: memory access
Reply With Quote #8

PHP Code:
set_taskdelay"Task_Search_Event_Entangle"TASK_ULTIMATE_ENTANGLE_SEARCH id );

//
// ...
//

public Task_Search_Event_Entangleid )
{
    
id -= TASK_ULTIMATE_ENTANGLE_SEARCH;

    
//
    // Your task code here
    //

    // Recursive set_task( )
    
set_taskdelay"Task_Search_Event_Entangle"TASK_ULTIMATE_ENTANGLE_SEARCH id );

_Master_ is offline
taheri6
Member
Join Date: Mar 2006
Old 01-11-2008 , 12:47   Re: Run time error 5: memory access
Reply With Quote #9

Are you saying that how I call the task is what is causing the memory problems??

Sorry, Im a little slow this morning, bare with me...
__________________
http://www.yaur.com -=[Yaur]=- Clan Website
taheri6 is offline
taheri6
Member
Join Date: Mar 2006
Old 01-13-2008 , 18:19   Re: Run time error 5: memory access
Reply With Quote #10

Ok, I got this to work, and actually I needed a few redundant checks as some times I would get array indexing errors every so often, but with redundant checks I have not gotten any and now the function is working as expected.

Thanks to all who helped.
__________________
http://www.yaur.com -=[Yaur]=- Clan Website
taheri6 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 11:11.


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