rhelgeby / sm-zombiereloaded

A plugin for SourceMod and Source server games that will change the game into a battle against zombies.
GNU General Public License v3.0
5 stars 2 forks source link

Fix ThrowNativeError and remove duplicate operation in zr_modulemanager #1

Closed LivingInPortal closed 10 years ago

LivingInPortal commented 10 years ago

ThrowNativeError should use in the native call, not in normal functions. Additionally, a duplicated operations in AddModuleToIndex RemoveModuleFromIndex functions removed.

LivingInPortal commented 10 years ago

If a ThrowNativeError be used in a normal function, a error "Not called from inside a native function" will be thrown, even if this is called from native function. Reference at: https://github.com/alliedmodders/sourcemod/blob/master/core/logic/smn_fakenatives.cpp#L138

rhelgeby commented 10 years ago

This is intentional. I've delegated validation down the layers and this error will propagate up to to the native function handler.

Think like exceptions bubbling up in an object oriented language.

Better ideas are welcome. I want to avoid complex validation in the native function handers to keep them simple and clean. I also want to throw errors from as close as possible to the relevant code. I wish SourceMod had a universal version of ThrowError so it could be used in both places, or at least so that I could decide whether it should fail internally or in the calling plugin.

Thanks for the review anyways.

LivingInPortal commented 10 years ago

Well, I might have to do some experiments to clear my misconceptions. I always be interested on Zombie Reloaded project, my favorite game mode, which is a reason for I started programming. I hope i can help something. Thanks! On Oct 26, 2014 4:22 PM, "Richard Helgeby" notifications@github.com wrote:

This is intentional. I've delegated validation down the layers and this error will propagate up to to the native function handler.

Think like exceptions bubbling up in an object oriented language.

Better ideas are welcome. I want to avoid complex validation in the native function handers to keep them simple and clean. I also want to throw errors from as close as possible to the relevant code. I wish SourceMod had a universal version of ThrowError so it could be used in both places, or at least so that I could decide whether it should fail internally or in the calling plugin.

— Reply to this email directly or view it on GitHub https://github.com/rhelgeby/sm-zombiereloaded/pull/1#issuecomment-60522612 .

rhelgeby commented 10 years ago

I made a thread about this issue. Maybe there's a better solution.

https://forums.alliedmods.net/showthread.php?t=250568

LivingInPortal commented 10 years ago

Yeah, this is really work out in a native. Sourcemod should call ThrowError rather than just call a warning when it doesn't come from a native.

rhelgeby commented 10 years ago

Looks like it really is redundant, so removal of "PushArrayCell(ModuleList, module);" is correct, though this should be a separate commit.

LivingInPortal commented 10 years ago

Pushed another commit