Raised This Month: $ Target: $400
 0% 

Invalid memory access Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zeroibis
Veteran Member
Join Date: Jun 2007
Old 07-18-2014 , 20:31   Invalid memory access Help
Reply With Quote #1

The code below produces the error: [SM] Plugin encountered error 11: Invalid memory access

But I do not understand why b/c it works find with a 1 dimensional array. Can someone please explain what I am doing wrong?

global var
Code:
new Handle:ItemWardTimer[MAXPLAYERS+1][2];
OnMapStart
Code:
Array_Fill2(ItemWardTimer, MAXPLAYERS+1, 2, INVALID_HANDLE);
in a stock include file
Code:
/**
 * Fills an array with a given value in a 2 dimensional static array.
 * You can specify the amount of cells to be written.
 *
 * @param array            Static Array.
 * @param size            Number of cells to write (eg. the array's size)
 * @param size3            Number of cells to write (eg. the array's size)
 * @param value            Fill value.
 * @param start            Optional: Offset where to start (0 - (size-1)).
 * @param start2        Optional: Offset where to start (0 - (size-1)).
 * @noreturn
 */
stock Array_Fill2(any:array[][], size, size2, any:value, start=0, start2=0)
{
    if(start < 0)
    {
        start = 0;
    }
    if(start2 < 0)
    {
        start2 = 0;
    }

    for(new i=start; i < size; i++)
    {
        for(new b=start2; b < size2; i++)
        {
            array[i][b] = value;
        }
    }
}
When it tries to do
Code:
array[i][b] = value;
it gives the error and I do not understand why.

The following below works just fine:

Global Var
Code:
new Handle:SpawnTimer[MAXPLAYERS+1];
OnMapStart
Code:
Array_Fill(SpawnTimer, MAXPLAYERS+1, INVALID_HANDLE);
in stock include file:
Code:
/**
 * Fills an array with a given value in a 1 dimensional static array.
 * You can specify the amount of cells to be written.
 *
 * @param array            Static Array.
 * @param size            Number of cells to write (eg. the array's size)
 * @param value            Fill value.
 * @param start            Optional: Offset where to start (0 - (size-1)).
 * @noreturn
 */
stock Array_Fill(any:array[], size, any:value, start=0)
{
    if (start < 0) {
        start = 0;
    }

    for (new i=start; i < size; i++) {
        array[i] = value;
    }
}
__________________
zeroibis is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 07-18-2014 , 21:23   Re: Invalid memory access Help
Reply With Quote #2

It has to be "b++" in the second for.

Cheers.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
zeroibis
Veteran Member
Join Date: Jun 2007
Old 07-18-2014 , 21:45   Re: Invalid memory access Help
Reply With Quote #3

wow I am stupid lol.

Thanks!
__________________
zeroibis is offline
zeroibis
Veteran Member
Join Date: Jun 2007
Old 10-27-2014 , 13:20   Re: Invalid memory access Help
Reply With Quote #4

I still get the error but only with this same array and only sometimes:
Code:
new bool:ClientHasItem[MAXPLAYERS+1][MAXITEMS+1];
Code:
public OnMapStart()
{
    Array_Fill2(ClientHasItem, MAXPLAYERS+1, W3GetItemsLoaded(), false);
}
It also occurs when I have: (which it was original I tried the above to see if it would fix it)
Code:

Code:
public OnMapStart()
{
    Array_Fill2(ClientHasItem, MAXPLAYERS+1, MAXITEMS+1, false);
}
Here is the stock again:
Code:
/**
 * Fills an array with a given value in a 2 dimensional static array.
 * You can specify the amount of cells to be written.
 *
 * @param array            Static Array.
 * @param size            Number of cells to write until (eg. the array's size)
 * @param size3            Number of cells to write until (eg. the array's size)
 * @param value            Fill value.
 * @param start            Optional: Offset where to start (0 - (size-1)).
 * @param start2        Optional: Offset where to start (0 - (size-1)).
 * @noreturn
 */
stock Array_Fill2(any:array[][], size, size2, any:value, start=0, start2=0)
{
    if(start < 0)
    {
        start = 0;
    }
    if(start2 < 0)
    {
        start2 = 0;
    }

    for(new i=start; i < size; i++)
    {
        for(new b=start2; b < size2; b++)
        {
            array[i][b] = value;
        }
    }
}
The war3 constraints has the following definition:
Code:
#define MAXITEMS 100  // [1]-[19] //(+1 of real number of items, if there are 8 items to load, use 9!! ignore zeroth rule)
The only thing I can think of is that MAXITEMS is being changed somewhere and thus causing problems.
__________________

Last edited by zeroibis; 10-27-2014 at 13:22.
zeroibis is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-27-2014 , 13:51   Re: Invalid memory access Help
Reply With Quote #5

I vaguely recall from conversations from a long time ago that SourcePawn has issues passing around multidimensional arrays.

I could be conflating this with natives not supporting them, though.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
zeroibis
Veteran Member
Join Date: Jun 2007
Old 10-27-2014 , 13:56   Re: Invalid memory access Help
Reply With Quote #6

The same program deals with 3 other 2 dimensional arrays without issue. It is explicitly only this one that gets effected.
__________________
zeroibis is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 10-27-2014 , 17:31   Re: Invalid memory access Help
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
I vaguely recall from conversations from a long time ago that SourcePawn has issues passing around multidimensional arrays.[...]
wat
Please stop talking to diablowhatshisface.

Maybe your arrays are different from mine, who knows. It works fine for me.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 10-27-2014 at 17:32.
Dr. Greg House is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 10-28-2014 , 07:38   Re: Invalid memory access Help
Reply With Quote #8

Hmm, i use multidimensional arrays that are huge and multi indexed and only run into this rarely. Usually it is because you are not passing the size of the array properly... Like it's a [][][] array, but you passed an indexed element of that array, which cuts its dimensions down to [][]. Sm doesn't notice this. Also, since strings are wierd, it confuses the dimensions.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.

Last edited by friagram; 10-28-2014 at 07:39.
friagram 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 07:54.


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