PDA

View Full Version : Simba Drawing



RlagkRud
03-16-2014, 11:22 PM
Hey guys! So I'm trying to draw on my SMART but I keep getting this error. My SRL is up to date.

Exception in Script: Runtime error: "Access violation" at line 51, column 17 in file "C:\Simba\Includes\SRL-6\lib\utilities\drawing.simba"
The following bitmaps were not freed: [Minimap Mask, Gametab Bitmap[0], Gametab Bitmap[1], Gametab Bitmap[2], Gametab Bitmap[3], Gametab Bitmap[4], Gametab Bitmap[5], Gametab Bitmap[6], Gametab Bitmap[7], Gametab Bitmap[8], Gametab Bitmap[9], Gametab Bitmap[10], Gametab Bitmap[11], Gametab Bitmap[12], Gametab Bitmap[13]]
File[C:\Simba\Includes\SRL-6/logs/SRL log (16-03-14 at 07.20.18 PM).txt] has not been freed in the script, freeing it now.

Olly
03-16-2014, 11:42 PM
Are you sure you enabled SMART drawing? (smartEnableDrawing := true, before setupSRL()).

RlagkRud
03-17-2014, 12:06 AM
Are you sure you enabled SMART drawing? (smartEnableDrawing := true, before setupSRL()).

Yep it's enabled. I'm trying to draw a box.
Should I be using TMufasaBitmap.drawBox or smartimage.drawbox?
I'm getting that same error for Tmufasa and smartimage doesn't cause an error but it doesn't draw.

RlagkRud
03-17-2014, 11:02 PM
Helpp preeze.
I want to release a script but I want the detection box to be drawn as a reference for people.
Any help or thought at all would be greatly appreciated.

Brandon
03-17-2014, 11:41 PM
Helpp preeze.
I want to release a script but I want the detection box to be drawn as a reference for people.
Any help or thought at all would be greatly appreciated.



{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
smartEnableDrawing := true;
SetupSRL;

smartImage.DrawBox(0, 0, 100, 100, true, clRed);
end.

Ashaman88
03-17-2014, 11:44 PM
Post the script for us

RlagkRud
03-18-2014, 12:17 AM
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
smartEnableDrawing := true;
SetupSRL;

smartImage.DrawBox(0, 0, 100, 100, true, clRed);
end.


This doesn't invoke an error but nothing is drawn on my screen. I guess I'll just have to accept it doesn't work on my simba. Weird.


Post the script for us

I will very soon. It's nothing too special of a script though.

Ashaman88
03-18-2014, 02:01 AM
Are you using ogl or dx?

RlagkRud
03-18-2014, 08:45 PM
Are you using ogl or dx?

dx

script is posted. lazyivy woodcutting

Olly
03-18-2014, 09:28 PM
dx

script is posted. lazyivy woodcutting

Does it draw in ogl mode?

RlagkRud
03-18-2014, 09:58 PM
Does it draw in ogl mode?

Oh wow it does work. I guess this is an issue with directx and SMART draw compatibility then?

Olly
03-18-2014, 10:41 PM
Oh wow it does work. I guess this is an issue with directx and SMART draw compatibility then?

Brandon

RlagkRud
03-18-2014, 11:45 PM
Just to provide more information for Brandon:

This is what I tested for OGL:

First ran this code:

{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
smartEnableDrawing := true;
SetupSRL;

smartImage.DrawBox(0, 0, 100, 100, true, clRed);
end.

When RS loaded, I turned off the script, logged in and changed my settings to OGL. Ran script again and the red box appeared.

Then I tested directx:

I quit out of SMART and ran this code:

{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
smartEnableDrawing := true;
smartPlugins := ['d3d9.dll'];
SetupSRL;

smartImage.DrawBox(0, 0, 100, 100, true, clRed);
end.

When RS loaded, I turned off the script, logged in and changed my settings to DirectX. Ran script again and the red box did NOT appear.

It also seems people using Clarity's Esswraith script is also facing a paint problem with DirectX. (http://villavu.com/forum/showthread.php?t=107894&page=2)

Ashaman88
03-19-2014, 12:12 AM
Doesn't he have a drawing and non-drawing version of the plugin?

Turpinator
03-19-2014, 12:46 AM
Yes, there is a problem with DX and drawing on smart.
It seems to only draw whenever DX is reinitialized. Try running your smartimage.draw() command and then nothing will appear. Switch to OGL and then back to DX... it should have drawn. yay!

RlagkRud
03-19-2014, 03:17 AM
Yes, there is a problem with DX and drawing on smart.
It seems to only draw whenever DX is reinitialized. Try running your smartimage.draw() command and then nothing will appear. Switch to OGL and then back to DX... it should have drawn. yay!

Yep this works. It'd be great if this was fixed though :D

Brotein
03-19-2014, 04:33 PM
I thought I was the only one doing something wrong when drawing wasn't working with Direct-X

Brandon
03-19-2014, 05:23 PM
Brandon

Thank you. I wasn't aware of anything until this tag. I was under the impression that drawing was working fine :S
I tested it today and yes it was completely broken. Not sure what changed recently in the client but I do know that its one of two things.. The Reset function is either not being called anymore or Present is being used now.. I'll look into it later. No detect-ability issues either way.

For now, here is a patch that will draw no matter what.. at the cost of a couple fps (creating the texture OpenGL style :l)
Hopefully it does NOT lag for you guys?

23100


So what changed? I removed an else statement and replaced it with a SafeRelease:


if (!Texture) /**See Device->Reset for more info.**/
{
LoadTexture(Device, static_cast<unsigned char*>(SmartGlobal->dbg), SmartGlobal->width, SmartGlobal->height, Texture);
}
/*else
{
memcpy(TexturePixels, SmartGlobal->dbg, SmartGlobal->width * SmartGlobal->height * 4);
}*/

DrawTexture(Device, Texture, 0, 0, SmartGlobal->width, SmartGlobal->height);
SafeRelease(Texture); //Delete Texture


I've mentioned before that I do not like drawing like that.. "Deleting the texture". I prefer the client do it only when it needs to. Anyway, this should work for sure..

One more thing I changed for those that messaged me a while back about a MessageBox error annoying them if their d3d9 is missing a certain function.. I replaced it with:


catch(std::exception &e)
{
//MessageBox(nullptr, e.what(), "ERROR!", 0);

CONSOLE_SCREEN_BUFFER_INFO Info;
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &Info);
int Attributes = Info.wAttributes;
SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
std::printf("\n\nDirect-X ERROR: %s\n\n\n", e.what());
SetConsoleTextAttribute(hStdout, Attributes);
}
return true;


This will no longer show a message box.. The plugin will not fail to load. Instead, it will simply tell you that there was an error (in red in Smart's console) and continue to load normally. If the error is fatal, it will instead not work. If the error is minor (as it always has been when you saw a messagebox), it will work fine. No it does not affect you in any way. It is simply there for debugging purposes and to let me know when things go down another path..

Sadly, no one ever reports anything :( Surprised I got tagged.. I'll be uploading the source for it today on Github as a new release. I think its a good one as drawing will always work. I will obviously find better ways to draw and update whenever I do.


EDIT:

https://github.com/Brandon-T/DXI/releases/tag/v0.4

Olly
03-19-2014, 05:36 PM
...

:) Thanks!

You change the colour of the console also? pretty neat :p

e: kinda offtopic but... - Brandon Can you try and raise a message box in a regular simba plugin in c++ for me? (the winAPI one) It always access violates for me via a fpc plugin... :( Wondering if it works in a c++ one though.

Brandon
03-19-2014, 06:51 PM
:) Thanks!

You change the colour of the console also? pretty neat :p

e: kinda offtopic but... - Brandon Can you try and raise a message box in a regular simba plugin in c++ for me? (the winAPI one) It always access violates for me via a fpc plugin... :( Wondering if it works in a c++ one though.

Yeah it works.. I can do it in FPC too (if you want)..

http://i.imgur.com/w3VYt3d.png

The code in C++ is:

main.cpp:

#include <windows.h>
#define EXPORT extern "C" __declspec(dllexport)



int ExportCount = 1;
char* Exports[] =
{
(char*)"MSGB", (char*)"Procedure MSG(Text, Caption: String);"
};

EXPORT void MSGB(const char* Text, const char* Caption)
{
MessageBox(NULL, Text, Caption, 0);
}




/** Don't worry about anything below **/

HINSTANCE hInstance = NULL;

EXPORT int GetPluginABIVersion()
{
return 2;
}

EXPORT int GetFunctionCount()
{
return ExportCount;
}

EXPORT int GetFunctionInfo(int Index, void*& Address, char*& Definition)
{
if (Index < ExportCount)
{
Address = reinterpret_cast<void*>(GetProcAddress(hInstance, Exports[Index * 2]));
strcpy(Definition, Exports[Index * 2 + 1]);
return Index;
}
return -1;
}

EXPORT bool __stdcall DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hInstance = hinstDLL;
break;
}
return true;
}

Olly
03-19-2014, 07:00 PM
Yeah it works.. I can do it in FPC too (if you want)..

Please do!

Brandon
03-19-2014, 07:45 PM
Please do!

Works and looks exactly like the C++ counterpart..


library MsgBox;

{$mode objfpc}{$H+}

uses
Classes, SysUtils, Windows;


Procedure MsgBox(Text, Caption: String); cdecl export;
begin
MessageBox(0, PChar(Text), PChar(Caption), 0); {*MessageBoxA(0, LPCSTR(Text), LPCSTR(Caption), 0);*}
end;

Function GetPluginABIVersion: Integer; cdecl export;
begin
Result := 2;
end;

Function GetFunctionCount: Integer; cdecl export;
begin
Result := 1;
end;

Function GetFunctionInfo(Index: Integer; var Address: Pointer; var Definition: PChar): Integer; cdecl export;
begin
case Index of
0:
begin
Address := @MsgBox;
StrPCopy(Definition, 'Procedure Msg(Text, Caption: String);');
end;
else
Exit(-1);
end;

Exit(Index);
end;

exports GetPluginABIVersion;
exports GetFunctionCount;
exports GetFunctionInfo;

begin
end.

Olly
03-19-2014, 07:50 PM
Works and looks exactly like the C++ counterpart..


library MsgBox;

{$mode objfpc}{$H+}

uses
Classes, SysUtils, Windows;


Procedure MsgBox(Text, Caption: String); cdecl export;
begin
MessageBox(0, PChar(Text), PChar(Caption), 0); {*MessageBoxA(0, LPCSTR(Text), LPCSTR(Caption), 0);*}
end;

Function GetPluginABIVersion: Integer; cdecl export;
begin
Result := 2;
end;

Function GetFunctionCount: Integer; cdecl export;
begin
Result := 1;
end;

Function GetFunctionInfo(Index: Integer; var Address: Pointer; var Definition: PChar): Integer; cdecl export;
begin
case Index of
0:
begin
Address := @MsgBox;
StrPCopy(Definition, 'Procedure Msg(Text, Caption: String);');
end;
else
Exit(-1);
end;

Exit(Index);
end;

exports GetPluginABIVersion;
exports GetFunctionCount;
exports GetFunctionInfo;

begin
end.


Not sure what i was doing wrong :S I'm pretty sure i was doing the exact same, whatever though thanks again :)

Brandon
03-19-2014, 07:51 PM
Not sure what i was doing wrong :S I'm pretty sure i was doing the exact same, whatever though thanks again :)

Works for you now? Could have just been calling conventions I guess.. That always bugs me.

RlagkRud
03-19-2014, 07:52 PM
drawing works now! I don't notice any fps decrease so that's good. Although the big red letters saying ERROR in the console is a bit unnerving ;)

Olly
03-19-2014, 08:05 PM
Works for you now? Could have just been calling conventions I guess.. That always bugs me.

Ya, works fine. :)