AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Dynamic Objects and Properties - v.0.0.32 - [2018.05.08] (https://forums.alliedmods.net/showthread.php?t=270519)

Neuro Toxin 08-21-2016 10:22

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
Refactor native logic
- Split internal logic code and native code to define an edge between them
- No internal code uses native calls anymore
- Fixed some bugs with Handles and Strings in the process

This update was to stop internal Dynamic calls from using it's own Natives. The benchmark has speed up again on add/read/update members.

Neuro Toxin 08-24-2016 05:30

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
Massive refactor with lots of changes
- Refactored all type code (Lots of small bugs fixed in the process)
- Added property OwnerPlugin
- Added Reset(bool disposemembers=true, int blocksize=0, int startsize=0)
- Added sm_dynamic_selftest command to ensure all Dynamic methods work as expected
- Finished partially completed type conversion between types Vector and String

PUNKSNOTDEAF 08-25-2016 05:01

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
New update works fine. I only get the following error each mapchange.

Code:

L 08/25/2016 - 10:24:03: Error log file session closed.
L 08/25/2016 - 10:24:04: SourceMod error session started
L 08/25/2016 - 10:24:04: Info (map "de_mirage") (file "errors_20160825.log")
L 08/25/2016 - 10:24:04: [SM] Exception reported: Could not read Handle b8490022 (error 1)
L 08/25/2016 - 10:24:04: [SM] Blaming: third/dynamic.smx()
L 08/25/2016 - 10:24:04: [SM] Call stack trace:
L 08/25/2016 - 10:24:04: [SM]  [0] GetPluginStatus
L 08/25/2016 - 10:24:04: [SM]  [1] Line 131, dynamic.sp::OnMapStart()


Neuro Toxin 08-25-2016 08:49

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
Steps towards FindByMemberValue(Dynamic params)
- Fixed .Push* methods not storing membernames correctly
- Fixed .CompareString/ByOffset
- Some more tests added to SelfTest
- First version of .FindByMemberValue
- Add garbage collection to OnLibraryRemoved forward
- Reset player settings on post disconnect
- Implement .Reset
- Implement .GetName properly
- Fix SelfTest reporting errors for Vector conversions

Quote:

Originally Posted by PUNKSNOTDEAF (Post 2448032)
New update works fine. I only get the following error each mapchange.

Code:

L 08/25/2016 - 10:24:03: Error log file session closed.
L 08/25/2016 - 10:24:04: SourceMod error session started
L 08/25/2016 - 10:24:04: Info (map "de_mirage") (file "errors_20160825.log")
L 08/25/2016 - 10:24:04: [SM] Exception reported: Could not read Handle b8490022 (error 1)
L 08/25/2016 - 10:24:04: [SM] Blaming: third/dynamic.smx()
L 08/25/2016 - 10:24:04: [SM] Call stack trace:
L 08/25/2016 - 10:24:04: [SM]  [0] GetPluginStatus
L 08/25/2016 - 10:24:04: [SM]  [1] Line 131, dynamic.sp::OnMapStart()


Be careful storing Handles. This makes me think a piece of code is calling delete on your handle, and is NOT calling .SetHandle("member", null);

Also update to the latest Dynamic master branch download as I had recently fixed a similar bug around Handles.

Chief149 08-26-2016 17:22

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
So I've been having an issue with setting some properties. dynamic.smx throws an exception basically.

The relevant part of my object's constructor:
Code:

public BClient(char steamid[64], int Client, bool loadFromDB = true)
{
        if(g_iLaser == -1)
                g_iLaser = PrecacheModel("materials/sprites/laserbeam.vmt", true);
               
        //the backing data structure
        Dynamic bc = Dynamic(256, 0);

        //one of the fields that wont work
        bc.SetInt("usingvendor", 0);

        //these lines only occur after EVERY field has been setup in the constructor
        if(loadFromDB)
                CreateTimer(3.0, LoadClient, bc);
        return view_as<BClient>(bc);
}

Here is the property code:
Code:

property int UsingVendor
{
        public get()
        {
                static int offset = INVALID_DYNAMIC_OFFSET;
                if(offset == INVALID_DYNAMIC_OFFSET)
                {
                        offset = this.GetMemberOffset("usingvendor");
                        if(offset == INVALID_DYNAMIC_OFFSET)
                                ThrowError("A serious error has occurred in Dynamic!");
                }
                return this.GetIntByOffset(offset);
        }
        public set(int i)
        {
                static int offset = INVALID_DYNAMIC_OFFSET;
                if(offset == INVALID_DYNAMIC_OFFSET)
                {
                        offset = this.GetMemberOffset("usingvendor");
                        if(offset == INVALID_DYNAMIC_OFFSET)
                        {
                                offset = this.SetInt("usingvendor", i);
                                return;
                        }
                }
                this.SetIntByOffset(offset, i);
        }
}

The code that triggers the error:
Code:

player.UsingVendor = 0;
//The error thrown to the console
Code:

L 08/26/2016 - 21:15:25: [SM] Exception reported: Invalid index 1 (count: 0)
L 08/26/2016 - 21:15:25: [SM] Blaming: dynamic.smx()
L 08/26/2016 - 21:15:25: [SM] Call stack trace:
L 08/26/2016 - 21:15:25: [SM]  [0] GetArrayCell
L 08/26/2016 - 21:15:25: [SM]  [1] Line 1199, C:\Users\Clayton\Dropbox\BluRP Dev\dynamic.sp::GetMemberType()
L 08/26/2016 - 21:15:25: [SM]  [2] Line 1527, C:\Users\Clayton\Dropbox\BluRP Dev\dynamic.sp::Native_Dynamic_SetIntByOffset()
L 08/26/2016 - 21:15:25: [SM]  [4] Dynamic_SetIntByOffset
L 08/26/2016 - 21:15:25: [SM]  [5] Line 201, C:\Users\Clayton\Dropbox\BluRP Dev\include\dynamic.inc::Dynamic.SetIntByOffset()
L 08/26/2016 - 21:15:25: [SM]  [6] Line 1166, C:\Users\Clayton\Dropbox\BluRP Dev\include\bluerp/classes/BClient.inc::BClient.UsingVendor.set()
L 08/26/2016 - 21:15:25: [SM]  [7] Line 1502, C:\Users\Clayton\Dropbox\BluRP Dev\include\bluerp/classes/BNpc.inc::JobHandle()

Is this an error on my end or with your plugin? I seem to be following everything correctly as far as I can tell. Judging by the error, I am pretty sure I am NOT trying to access a property of an invalid dynamic object.

SM9 08-26-2016 18:22

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
It appears .Membercount does not decrement when a child is disposed. I believe this is the cause of my loops getting slower + possibly memory leaks with stack constantly increasing?

Neuro Toxin 08-26-2016 20:49

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
Quote:

Originally Posted by Chief149 (Post 2448545)
Is this an error on my end or with your plugin? I seem to be following everything correctly as far as I can tell. Judging by the error, I am pretty sure I am NOT trying to access a property of an invalid dynamic object.

The error is indicating that your dynamic object wasn't initialised before setting a member.

Please download / install / update your plugins to the current unreleased version.

Please also refer to this new methodmap structure. The offsets have been removed to avoid corruption with non uniform objects. It also cleans up your methodmaps and makes them easier to manage.

Neuro Toxin 08-26-2016 20:57

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
Quote:

Originally Posted by xCoderx (Post 2448552)
It appears .Membercount does not decrement when a child is disposed. I believe this is the cause of my loops getting slower + possibly memory leaks with stack constantly increasing?

Dynamic cant remove members and have the member count decrease.

You need to reuse members or use .Reset(*) to clean its members.

You may be after a collection which allows you to remove objects.

Edit: You can also override a collections Items function to return your own methodmap.

Chief149 08-26-2016 21:03

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
I suspected that there may have been updates to your plugin, so I downloaded the latest version. This didn't fix the problem.

The constructor initializes every single member. Even if it doesn't, I know for certain that I initialized the one class member that is shown in my post.

How long does it take for your plugin to initialize a dynamic object once the constructor is called? Because in this case that object was a client object. BClient is created when a player joins the game. This error occurred a couple minutes later.

How does the efficiency compare between the new methodmap structure and the old one? I have thousands of lines worth of classes coded with the older methodmap structure.

What I find really odd is that other members do work, but some also don't work. I have checked many times to make sure I didn't misspell the member name in the constructor or property.

Neuro Toxin 08-26-2016 21:20

Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
 
To confirm. The index out of bounds error is saying your dynamic object is invalid. It doesnt relate to the member your trying to access.

Maybe add a check like .IsValid just before your error line.

Dynamic objects are initialised instantly.

The "class" method your using is like .01 faster over 100K member iterations which is nothing really. The class code is safe if noone accesses the dynamic object from outside your class.

By removing the offsets and doing methodmaps based on the last post to you: you should remove those pesky and hard to debug issues when your checking the member names in the initialiser and properties. It also makes the code heaps easier to manage. Imo, this outweighs the ever so slight performance boost.

When i get weird issues with members. I dump the object using .WriteKeyValues. This is the best way to check your data is right.


All times are GMT -4. The time now is 00:16.

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