ENIGMA Forums

Outsourcing saves money => Programming Help => Topic started by: lonewolff on September 28, 2014, 11:00:24 pm

Title: [Solved] Adding a new function
Post by: lonewolff on September 28, 2014, 11:00:24 pm
If I were to add the window_device() function to ENIGMA (in the DX9 renderer) what file would I start with?

Just trying to keep the standard as to how you guys like to do things.
Title: Re: Adding a new function.
Post by: lonewolff on September 28, 2014, 11:37:54 pm
Ok, from talking on the IRC the best place for this is DX9Context.h

I have added this but LGM still doesn't know about the window_handle() function.

So, the big question is - If you add a new GML command say 'boo()' (for example) how does ENIGMA know what this new function belongs to in the source code. Or is just having the function name 'boo' in the source code enough?
Title: Re: Adding a new function.
Post by: sorlok_reaves on September 28, 2014, 11:45:49 pm
JDI should auto-detect any functions added to the enigma_user namespace.
Title: Re: Adding a new function.
Post by: lonewolff on September 28, 2014, 11:47:26 pm
JDI should auto-detect any functions added to the enigma_user namespace.

That was the part I didn't know. :)

Just testing now.  (Y)
Title: Re: Adding a new function.
Post by: lonewolff on September 28, 2014, 11:52:43 pm
Ok I just added a new function 'test' in WINDOWSMain.h

Code: [Select]
namespace enigma_user
{
   unsigned long long window_handle();
   int sleep(int millis);

   void test();
}


And defined the function in DX9Context.h

Code: [Select]
void test()
{
   return;
}

and this

Code: [Select]
void enigma_user::test()
{
   return;
}

But the compiler says this

Quote
C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/SHELLmain.o:SHELLmain.cpp:(.text+0x1bb): undefined reference to `enigma_user::test()'

Any ideas what is going wrong?
Title: Re: Adding a new function.
Post by: sorlok_reaves on September 28, 2014, 11:59:23 pm
Are you sure that last definition is not inside another namespace? (Also, it should probably be inside a .cpp file.)
Title: Re: Adding a new function.
Post by: Goombert on September 29, 2014, 12:25:49 am
He got it sorlok.

Platforms/General/PFwindow.h
Code: (cpp) [Select]
namespace enigma_user {
void* window_device();
}

Bridges/Win32-Direct3D9/graphics_bridge.cpp
Code: (cpp) [Select]
namespace enigma_user {
void* window_device() {
  return enigma::d3dmgr->device;
}
}

The reason I never sent this to master was because I didn't know how far we could throw it.
Title: Re: Adding a new function.
Post by: lonewolff on September 29, 2014, 12:31:27 am
Yep, that side compiles ok now :)

Making a simple DLL to test that it actually works.

That will take a little while, so I'll get back to you Rob :)
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 12:56:15 am
Overall it fails I am afraid (project works fine in GM:S I had better add).

Probably something to do with whow you handle external DLL's or something (only guessing).

Quote
Building for mode (0)
Cleaning up from previous executions
 - Cleared parsed objects
 - Cleared room entries
 - Cleared shared locals list
 - Cleared event info
Loading shared locals from extensions list
Location in memory of structure: 49ff86b8
Copying resources:
Copying sprite names

Copying sound names

Copying background names

Copying path names

Copying script names

Copying shader names

Copying font names [1]
Copying timeline names

Copying object names [1]
Copying room names [1]
SYNTAX CHECKING AND PRIMARY PARSING:
0 Scripts:
"Linking" scripts
`Linking' 0 scripts and 0 timelines in 0 passes...
Completing script "Link"
Done.
Completing timeline "Link"
Done.
1 Objects:
 obj_quad: 12 events:
  Event[0]:   Parsing 1 sub-events:
Check `obj_quad::create... Done. Parse... Done.
  Event[8]:   Parsing 1 sub-events:
Check `obj_quad::draw... Done. Parse... Done.
Creating room creation code scope and parsing
"Linking" scripts into the objects...
"Linking" timelines into the objects...
"Link" complete.
Tabulating maximum argument passes to each script
Finished
Writing executable information and resources.
Writing modes and settings
Writing object switch
Writing resource names and maxima
Writing timeline control information
Writing events
Linking globals
Running Secondary Parse Passes
Writing object data
Writing local accessors
Writing font data
Writing room data
Writing shader data
Running make from `mingw32-make.exe'
Full command line: mingw32-make.exe Game WORKDIR="C:/ProgramData/ENIGMA/" GMODE=Run GRAPHICS=OpenGL1 AUDIO=OpenAL COLLISION=Precise WIDGETS=Win32 NETWORKING=None PLATFORM=Win32 CXXFLAGS="-I../Additional/i686-w64-mingw32/include" COMPILEPATH="Windows/Windows" EXTENSIONS=" Universal_System/Extensions/Alarms Universal_System/Extensions/Timelines Universal_System/Extensions/Paths Universal_System/Extensions/MotionPlanning Universal_System/Extensions/DateTime Universal_System/Extensions/ParticleSystems Universal_System/Extensions/DataStructures" OUTPUTNAME="D:/Users/Jason/AppData/Local/Temp/egm3653980965690431824.exe" eTCpath=""
mingw32-make.exe -C ENIGMAsystem/SHELL
mingw32-make.exe[1]: Entering directory `D:/Users/Jason/Downloads/ENIGMA/enigma-dev/ENIGMAsystem/SHELL'
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Audio_Systems/OpenAL/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Bridges/Win32-OpenGL1/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Collision_Systems/Precise/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Graphics_Systems/General/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Graphics_Systems/OpenGL1/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Platforms/Win32/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Universal_System/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Universal_System/Extensions/Alarms/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Universal_System/Extensions/DataStructures/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Universal_System/Extensions/DateTime/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Universal_System/Extensions/MotionPlanning/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Universal_System/Extensions/ParticleSystems/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Universal_System/Extensions/Paths/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Universal_System/Extensions/Timelines/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/Widget_Systems/Win32/
g++ -I../Additional/i686-w64-mingw32/include -IPlatforms/Win32/Info -IGraphics_Systems/OpenGL1/Info -IAudio_Systems/OpenAL/Info -ICollision_Systems/Precise/Info -IWidget_Systems/Win32/Info -INetworking_Systems/None/Info -IUniversal_System/Info -I. -IC:/ProgramData/ENIGMA/ -Wall -s -O3 -fno-exceptions  -MMD -MP -c -o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Run/SHELLmain.o SHELLmain.cpp
In file included from SHELLmain.cpp:107:0:
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h: In member function 'virtual variant enigma::OBJ_obj_quad::myevent_create()':
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:46:40: error: conversion from 'void*' to 'variant' is ambiguous
     external_call(init, window_device());
                                        ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:46:39: note: candidates are:
     external_call(init, window_device());
                                       ^
In file included from Universal_System/var4.h:36:0,
                 from SHELLmain.cpp:28:
Universal_System/var4.h:92:29: note: variant::variant(const char*) <near match>
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:111:2: note: in definition of macro 'types_extrapolate_string_p'
  prefix (const char *x) EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note:   no known conversion for argument 1 from 'void*' to 'const char*'
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:111:2: note: in definition of macro 'types_extrapolate_string_p'
  prefix (const char *x) EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note: variant::variant(long long unsigned int) <near match>
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:46:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (unsigll x)   EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note:   no known conversion for argument 1 from 'void*' to 'long long unsigned int'
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:46:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (unsigll x)   EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note: variant::variant(long long int) <near match>
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:45:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (long long x) EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note:   no known conversion for argument 1 from 'void*' to 'long long int'
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:45:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (long long x) EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note: variant::variant(unsigned int) <near match>
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:44:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (unsigned x)  EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note:   no known conversion for argument 1 from 'void*' to 'unsigned int'
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:44:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (unsigned x)  EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note: variant::variant(long unsigned int) <near match>
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:43:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (unsigl x)    EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note:   no known conversion for argument 1 from 'void*' to 'long unsigned int'
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:43:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (unsigl x)    EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note: variant::variant(long int) <near match>
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:42:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (long x)      EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note:   no known conversion for argument 1 from 'void*' to 'long int'
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:42:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (long x)      EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note: variant::variant(int) <near match>
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:41:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (int x)       EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
Universal_System/var4.h:92:29: note:   no known conversion for argument 1 from 'void*' to 'int'
   types_extrapolate_alldecc(variant)
                             ^
Universal_System/var_te.h:41:2: note: in definition of macro 'types_extrapolate_real_p'
  prefix (int x)       EVCONST suffix\
  ^
Universal_System/var4.h:92:3: note: in expansion of macro 'types_extrapolate_alldecc'
   types_extrapolate_alldecc(variant)
   ^
In file included from ./Platforms/Win32/include.h:7:0,
                 from C:/ProgramData/ENIGMA/API_Switchboard.h:31,
                 from SHELLmain.cpp:58:
./Platforms/Win32/../General/PFexternals.h:36:9: error:   initializing argument 2 of 'variant enigma_user::external_call(int, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant)'
 variant external_call(int id,variant a1=0,variant a2=0,variant a3=0,variant a4=0,variant a5=0,variant a6=0,variant a7=0,variant a8=0,
         ^
mingw32-make.exe[1]: Leaving directory `D:/Users/Jason/Downloads/ENIGMA/enigma-dev/ENIGMAsystem/SHELL'
mingw32-make.exe: *** [Game] Error 2

Oh and this is how I am interfacing with GM:S to let you know. I even changed the argument to a void* to make sure it fits with what we did to the source, Rob.

Code: [Select]
export double init(void* mD3dDevice)
{
d3dDevice=(IDirect3DDevice9*)mD3dDevice;

if(!d3dDevice)
return 1;

return 0;
}
Title: Re: [Solved] Adding a new function
Post by: Goombert on September 29, 2014, 01:00:45 am
Yeah, variant can not overload void* I am not sure how hard it would be to make it do that, but if we want pointers it needs to anyway. Regular pointers do work though, if u wanted to use that inside a script it might work as in window_device()->SomeD3DFunction();
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 01:04:18 am
Yeah, variant can not overload void* I am not sure how hard it would be to make it do that, but if we want pointers it needs to anyway. Regular pointers do work though, if u wanted to use that inside a script it might work as in window_device()->SomeD3DFunction();

LOL - nope not sure what you mean.

This is what I have in the calling script if that helps

Code: [Select]
dll_name="t.dll";

init=external_define(dll_name,"init",dll_cdecl,ty_real,1,ty_string);
create_quad=external_define(dll_name,"createQuad",dll_cdecl,ty_real,0);
draw_quad=external_define(dll_name,"drawQuad",dll_cdecl,ty_real,0);

external_call(init,window_device());
external_call(create_quad);
Title: Re: [Solved] Adding a new function
Post by: Goombert on September 29, 2014, 01:05:58 am
Make a blank game with window_device()->EndScene(); and tell me if it compiles.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 01:09:08 am
Make a blank game with window_device()->EndScene(); and tell me if it compiles.

Line 3, position 17 (absolute 50): Expected primary expression before operator
Title: Re: [Solved] Adding a new function
Post by: Goombert on September 29, 2014, 01:13:13 am
Parsing fail, we don't support -> yet I suppose. So yeah variant just needs overloaded with void*.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 01:15:34 am
Parsing fail, we don't support -> yet I suppose. So yeah variant just needs overloaded with void*.

So that is something you need to do on the ENIGMA source?
Title: Re: [Solved] Adding a new function
Post by: Goombert on September 29, 2014, 01:18:58 am
Something somebody needs to do if we want pointer types. First the compiler has to support parsing it, only sorlok could probably pull that off, too complex for me. Second variant type needs overloaded, I've tried overloading it myself for arrays before, and it was hell and I gave up.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 01:21:04 am
Bummer.

Looks like this is what needs to be done if window_device() and window_handle() want to work as per GM:S.

Having said that, does window_handle() work in ENIGMA in its current form?
Title: Re: [Solved] Adding a new function
Post by: time-killer-games on September 29, 2014, 01:32:31 am
^it works with GM81 casted dll's. But with GMS specific dll's have no idea,
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 01:53:21 am
Trying to cast from a double to a device but it is failing (returns 1)

Code: [Select]
export double init(double mD3dDevice)
{
void* temp=&mD3dDevice;

d3dDevice=(IDirect3DDevice9*)temp;

if(!d3dDevice)
return 1;

return 0;
}

If we can force a cast, I am confident the whole thing will still work.
Title: Re: [Solved] Adding a new function
Post by: DaSpirit on September 29, 2014, 05:47:33 am
Why not use C++?

If we can force a cast, I am confident the whole thing will still work.
Yes, C++ has that. It's called reinterpret_cast<T>.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 06:35:12 am
I can now get a return value of zero (which is good-ish), but still not sure if it is casting to a correct value as my next call (create_buffer()) in the DLL is always failing INVALID_CALL. (Normally caused by a dodgy D3D device from experience)

So, I am not completely confident I am referencing the right part of memory.

Also the window_device() function Rob helped me to write into the source is interesting.

If I draw_text(20,20, string(window_device())) in GM:S, I get a hexadecimal value 8 characters or so (not on my PC now) and if I make the same call in ENIGMA, I get a decimal value of about 12 digits or so.

So either ENIGMA's string() function is not quite right or something funky is going on.
Title: Re: [Solved] Adding a new function
Post by: TheExDeus on September 29, 2014, 06:39:38 am
I don't think GM:S prints text in hexadecimal. It could be possible GM:S shows 8 decimal digits, but ENIGMA show 12 digits. It's just a matter of taste.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 06:53:49 am
Definitely displays window_device() in hexadecimal on GM:S.  (Y)

Definitely... :)
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on September 29, 2014, 08:21:15 am
I can definitely re-write var/variant to hold and dispense a void pointer, but I'd really like some input from Josh on this. In particular, I'd like to know what the user-level interface for extracting a pointer would be like, and how it would gracefully fail. I assume something like this:

Code: [Select]
variant::variant(const void* p): rval(0), sval(), pval(p), type(ptr) { }
const void* some_function_to_get_the_ptr() { return (type==ptr) ? p : 0; }
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 29, 2014, 05:07:30 pm
I can definitely re-write var/variant to hold and dispense a void pointer, but I'd really like some input from Josh on this. In particular, I'd like to know what the user-level interface for extracting a pointer would be like, and how it would gracefully fail. I assume something like this:

Code: [Select]
variant::variant(const void* p): rval(0), sval(), pval(p), type(ptr) { }
const void* some_function_to_get_the_ptr() { return (type==ptr) ? p : 0; }

I think it was you, that Rob mentioned to me, with regards to this (yesterday). And he did say something about you having to write a variant.

If this could be written in, it would be awesome ;)

As it stands window_handle() is implemented incorrectly in ENIGMA also (as it is a pointer, like window_device())

(This information was supplied to me by Russell Kay BTW - so not just making 'shit' up)  (Y)
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on September 30, 2014, 10:33:54 pm
I think it was you, that Rob mentioned to me, with regards to this (yesterday). And he did say something about you having to write a variant.

Just a quick update; I'm all over the country this week, so I'm afraid this feature will be slightly delayed. (Frustrating, I know.) I actually brought an external hard drive with my dev. environment on it, but I forgot my Super Grub CD (do'h!) so it's just a brick.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on September 30, 2014, 11:00:24 pm
No probs. Let me know when you get a chance. No rush.  (Y)
Title: Re: [Solved] Adding a new function
Post by: Goombert on October 01, 2014, 01:52:06 am
Hey it's ok sorlok! Enjoy yourself and I hope you have a nice time!
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 02, 2014, 03:12:20 pm
Ok, this is just a proof-of-concept, but it *should* work. Please merge this commit to your local repo:
https://github.com/sorlok/enigma-dev/compare/enigma-dev:master...sorlok:hacky_pointers

...and then do something like this:
Code: [Select]
export double init(variant mD3dDevice)
{
void* temp = temp_get_pointer(mD3dDevice);
}

You should also modify your init code to print the pointer address of mD3dDevice the first time it is created. Then compare that value to temp and make sure we're at least looking at the right location in memory.

If that works, try actually using the pointer.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 02, 2014, 05:58:52 pm
Hi Sorlok,

Still getting compilation errors, so I'll list everything I have done today (incase I have confused myself and done something silly).

1st updated the files you linked in your post.

Code: [Select]
// Added window_device to WINDOWSmain.h

namespace enigma_user
{

unsigned long long window_handle();
int sleep(int millis);
void* window_device();

}

Code: [Select]
// added window_device towards the end of graphics_bridge.cpp

void* window_device()
{
return (void*)d3dmgr->device;
}

Now getting compilation errrors

Quote
Running make from `mingw32-make.exe'
Full command line: mingw32-make.exe Game WORKDIR="C:/ProgramData/ENIGMA/" GMODE=Compile GRAPHICS=OpenGL1 AUDIO=OpenAL COLLISION=Precise WIDGETS=Win32 NETWORKING=None PLATFORM=Win32 CXXFLAGS="-I../Additional/i686-w64-mingw32/include" COMPILEPATH="Windows/Windows" EXTENSIONS=" Universal_System/Extensions/Alarms Universal_System/Extensions/Timelines Universal_System/Extensions/Paths Universal_System/Extensions/MotionPlanning Universal_System/Extensions/DateTime Universal_System/Extensions/ParticleSystems Universal_System/Extensions/DataStructures" OUTPUTNAME="D:/Users/Jason/Desktop/_aaa.exe" eTCpath=""
mingw32-make.exe -C ENIGMAsystem/SHELL
mingw32-make.exe[1]: Entering directory `D:/Users/Jason/Downloads/ENIGMA/enigma-dev/ENIGMAsystem/SHELL'
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Audio_Systems/OpenAL/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Bridges/Win32-OpenGL1/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Collision_Systems/Precise/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Graphics_Systems/General/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Graphics_Systems/OpenGL1/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Platforms/Win32/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/Alarms/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/DataStructures/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/DateTime/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/MotionPlanning/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/ParticleSystems/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/Paths/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/Timelines/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Widget_Systems/Win32/
g++ -I../Additional/i686-w64-mingw32/include -IPlatforms/Win32/Info -IGraphics_Systems/OpenGL1/Info -IAudio_Systems/OpenAL/Info -ICollision_Systems/Precise/Info -IWidget_Systems/Win32/Info -INetworking_Systems/None/Info -IUniversal_System/Info -I. -IC:/ProgramData/ENIGMA/ -Wall -s -O3 -flto -fno-exceptions -fdata-sections -ffunction-sections  -MMD -MP -c -o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Bridges/Win32-OpenGL1/graphics_bridge.o Bridges/Win32-OpenGL1/graphics_bridge.cpp
g++ -I../Additional/i686-w64-mingw32/include -IPlatforms/Win32/Info -IGraphics_Systems/OpenGL1/Info -IAudio_Systems/OpenAL/Info -ICollision_Systems/Precise/Info -IWidget_Systems/Win32/Info -INetworking_Systems/None/Info -IUniversal_System/Info -I. -IC:/ProgramData/ENIGMA/ -Wall -s -O3 -flto -fno-exceptions -fdata-sections -ffunction-sections  -MMD -MP -c -o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Platforms/Win32/WINDOWSthreads.o Platforms/Win32/WINDOWSthreads.cpp
g++ -I../Additional/i686-w64-mingw32/include -IPlatforms/Win32/Info -IGraphics_Systems/OpenGL1/Info -IAudio_Systems/OpenAL/Info -ICollision_Systems/Precise/Info -IWidget_Systems/Win32/Info -INetworking_Systems/None/Info -IUniversal_System/Info -I. -IC:/ProgramData/ENIGMA/ -Wall -s -O3 -flto -fno-exceptions -fdata-sections -ffunction-sections  -MMD -MP -c -o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Platforms/Win32/WINDOWSmain.o Platforms/Win32/WINDOWSmain.cpp
Platforms/Win32/WINDOWSmain.cpp: In function 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)':
Platforms/Win32/WINDOWSmain.cpp:218:25: warning: unused variable 'wmain' [-Wunused-variable]
     WNDCLASS wcontainer,wmain;
                         ^
g++ -I../Additional/i686-w64-mingw32/include -IPlatforms/Win32/Info -IGraphics_Systems/OpenGL1/Info -IAudio_Systems/OpenAL/Info -ICollision_Systems/Precise/Info -IWidget_Systems/Win32/Info -INetworking_Systems/None/Info -IUniversal_System/Info -I. -IC:/ProgramData/ENIGMA/ -Wall -s -O3 -flto -fno-exceptions -fdata-sections -ffunction-sections  -MMD -MP -c -o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Platforms/Win32/WINDOWSjoystick.o Platforms/Win32/WINDOWSjoystick.cpp
g++ -I../Additional/i686-w64-mingw32/include -IPlatforms/Win32/Info -IGraphics_Systems/OpenGL1/Info -IAudio_Systems/OpenAL/Info -ICollision_Systems/Precise/Info -IWidget_Systems/Win32/Info -INetworking_Systems/None/Info -IUniversal_System/Info -I. -IC:/ProgramData/ENIGMA/ -Wall -s -O3 -flto -fno-exceptions -fdata-sections -ffunction-sections  -MMD -MP -c -o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/SHELLmain.o SHELLmain.cpp
mingw32-make.exe[1]: Leaving directory `D:/Users/Jason/Downloads/ENIGMA/enigma-dev/ENIGMAsystem/SHELL'
mingw32-make.exe[1]: Entering directory `D:/Users/Jason/Downloads/ENIGMA/enigma-dev/ENIGMAsystem/SHELL'
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Audio_Systems/OpenAL/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Bridges/Win32-OpenGL1/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Collision_Systems/Precise/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Graphics_Systems/General/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Graphics_Systems/OpenGL1/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Platforms/Win32/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/Alarms/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/DataStructures/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/DateTime/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/MotionPlanning/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/ParticleSystems/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/Paths/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/Timelines/
mkdir.exe -p C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Widget_Systems/Win32/
echo "// GENERATED RESOURCE FILE FRONTEND" > C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/resources.rc
for res in Preprocessor_Environment_Editable/Resources.rc Widget_Systems/Win32/getstring.rc Widget_Systems/Win32/getlogin.rc Widget_Systems/Win32/showinfo.rc Widget_Systems/Win32/showmessageext.rc; do echo "#include \"$res\"" >> C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/resources.rc; done
windres.exe -o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/resources.res -I. -IC:/ProgramData/ENIGMA/ C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/resources.rc -O coff
xtensions/ParticleSystems/PS_particle_system.o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Universal_System/Extensions/DataStructures/data_structures.o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Bridges/Win32-OpenGL1/graphics_bridge.o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/resources.res -lffi -lcomdlg32 -lgdi32 -lwinmm -lwininet -lopengl32 -lglu32 -lALURE32-static -lOpenAL32 -lvorbisfile -lvorbis -logg -lFLAC -lsndfile -lmodplug -lmpg123 -lole32 -lwinmm -lcomctl32 -luuid -lole32 -lz
windres.exe: warning: 24: 1: 1033: duplicate value
windres.exe: warning: 24: 1: 1033: duplicate value
windres.exe: warning: 24: 1: 1033: duplicate value
g++ -flto -s -O3 -L../Additional/i686-w64-mingw32/lib -static-libgcc -static-libstdc++ -static-libgcc -Wl,-subsystem,windows -o "D:/Users/Jason/Desktop/_aaa.exe"

[snipped to fit the max forum post size]

C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/Bridges/Win32-OpenGL1/graphics_bridge.o C:/ProgramData/ENIGMA/.eobjs/Windows/Windows/Compile/resources.res -lffi -lcomdlg32 -lgdi32 -lwinmm -lwininet -lopengl32 -lglu32 -lALURE32-static -lOpenAL32 -lvorbisfile -lvorbis -logg -lFLAC -lsndfile -lmodplug -lmpg123 -lole32 -lwinmm -lcomctl32 -luuid -lole32 -lz
Universal_System/instance_system.cpp:185:14: warning: type of 'object_idmax' does not match original declaration [enabled by default]
   extern int object_idmax;
              ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_resourcenames.h:37:27: note: previously declared here
 namespace enigma { size_t object_idmax = 1; }
                           ^
Universal_System/resource_data.cpp:36:14: warning: type of 'script_idmax' does not match original declaration [enabled by default]
   extern int script_idmax;
              ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_resourcenames.h:117:27: note: previously declared here
 namespace enigma { size_t script_idmax = 0; }
                           ^
Universal_System/roomsystem.cpp:214:14: warning: type of 'room_idmax' does not match original declaration [enabled by default]
   extern int room_idmax;
              ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_resourcenames.h:140:27: note: previously declared here
 namespace enigma { size_t room_idmax = 1; }
                           ^
D:\Users\Jason\AppData\Local\Temp\ccD9ph1j.ltrans20.ltrans.o:ccD9ph1j.ltrans20.o:(.text+0x540): undefined reference to `enigma_user::window_device()'
D:\Users\Jason\AppData\Local\Temp\ccD9ph1j.ltrans21.ltrans.o:ccD9ph1j.ltrans21.o:(.text+0x414): undefined reference to `enigma_user::window_device()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [compile_game] Error 1
mingw32-make.exe[1]: Leaving directory `D:/Users/Jason/Downloads/ENIGMA/enigma-dev/ENIGMAsystem/SHELL'
mingw32-make.exe: *** [Game] Error 2
Universal_System/instance_system.cpp:185:14: warning: type of 'object_idmax' does not match original declaration [enabled by default]
   extern int object_idmax;
              ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_resourcenames.h:37:27: note: previously declared here
 namespace enigma { size_t object_idmax = 1; }
                           ^
Universal_System/resource_data.cpp:36:14: warning: type of 'script_idmax' does not match original declaration [enabled by default]
   extern int script_idmax;
              ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_resourcenames.h:117:27: note: previously declared here
 namespace enigma { size_t script_idmax = 0; }
                           ^
Universal_System/roomsystem.cpp:214:14: warning: type of 'room_idmax' does not match original declaration [enabled by default]
   extern int room_idmax;
              ^
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_resourcenames.h:140:27: note: previously declared here
 namespace enigma { size_t room_idmax = 1; }
                           ^
D:\Users\Jason\AppData\Local\Temp\ccD9ph1j.ltrans20.ltrans.o:ccD9ph1j.ltrans20.o:(.text+0x540): undefined reference to `enigma_user::window_device()'
D:\Users\Jason\AppData\Local\Temp\ccD9ph1j.ltrans21.ltrans.o:ccD9ph1j.ltrans21.o:(.text+0x414): undefined reference to `enigma_user::window_device()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [compile_game] Error 1
mingw32-make.exe[1]: Leaving directory `D:/Users/Jason/Downloads/ENIGMA/enigma-dev/ENIGMAsystem/SHELL'
mingw32-make.exe: *** [Game] Error 2

Hopefully you guys can make sense of this. MinGW compiler messages are not my srtong point.
Title: Re: [Solved] Adding a new function
Post by: Goombert on October 02, 2014, 06:09:14 pm
Those are actually warnings, you only have one error actually.
D:\Users\Jason\AppData\Local\Temp\ccD9ph1j.ltrans20.ltrans.o:ccD9ph1j.ltrans20.o:(.text+0x540): undefined reference to `enigma_user::window_device()'
D:\Users\Jason\AppData\Local\Temp\ccD9ph1j.ltrans21.ltrans.o:ccD9ph1j.ltrans21.o:(.text+0x414): undefined reference to `enigma_user::window_device()'

When you moved window_device, did you leave it in namespace enigma_user {} ?
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 02, 2014, 06:23:06 pm
Line 40 in WINDOWSMain.h (right inside namespace enigma_user {} )

void* window_device();
Title: Re: [Solved] Adding a new function
Post by: Goombert on October 02, 2014, 06:23:57 pm
No, in the source (graphics_bridge.cpp)?
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 02, 2014, 06:30:00 pm
Oh as in like this?

void* enigma_user::window_device()?

Nope, although it worked the ther day without enigma_user:: at the front.

My daughter is on my PC right now, so will test in a bit. :)

[off topic]
I just found out I get a Win8 tablet today. Work is feeling generous! Happy days! :)
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 02, 2014, 08:00:06 pm
Just tried this in graphics_bridge.cpp

Code: [Select]
void* enigma_user::window_device()
{
return (void*)d3dmgr->device;
}

Still the same error.

I am sure I am making a silly mistake somewhere. :(

[edit]
** Damn! This default OpenGL thing gets me every time..... LOL
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 02, 2014, 08:05:30 pm
Just tried this in graphics_bridge.cpp

Code: [Select]
void* enigma_user::window_device()
{
return (void*)d3dmgr->device;
}

Still the same error.

I am sure I am making a silly mistake somewhere. :(

Is window_device() inside some other namespace? Like enigma{} maybe? Or can you post both files?
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 02, 2014, 08:11:32 pm
I just Ninja'd you.

I had project settings on OpenGL  ::)

Not used to the defaults on ENIGMA.  :D

Compiled fine but app still crashes when trying to draw a textured quad. So, more investigating at my end now (DLL works fine in GM:S)
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 02, 2014, 08:19:14 pm
I just Ninja'd you.

I had project settings on OpenGL  ::)

Not used to the defaults on ENIGMA.  :D

Compiled fine but app still crashes when trying to draw a textured quad. So, more investigating at my end now (DLL works fine in GM:S)

Can you print the pointer and make sure it's actually pointing to the same memory location?
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 02, 2014, 08:21:48 pm
Yep, just looking now. Project became seriously garbled. Starting a new one  (Y)
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 02, 2014, 08:38:42 pm
Still crashes on my create_quad() call, even though the window_device seems to be returning a good value :)

So this is what I have.

Create event
Code: [Select]
dll_name="t.dll";

init=external_define(dll_name,"init",dll_cdecl,ty_real,1,ty_string);
create_quad=external_define(dll_name,"createQuad",dll_cdecl,ty_real,0);
draw_quad=external_define(dll_name,"drawQuad",dll_cdecl,ty_real,0);

aaa=external_call(init,window_device());
bbb=external_call(create_quad);            // *** THIS IS CAUSING ENIGMA TO CRASH ***

Part of the DLL
Code: [Select]
export double init(void* mD3dDevice)
{
d3dDevice=(IDirect3DDevice9*)mD3dDevice;

if(!d3dDevice)
return 1000;

return 0;
}

The above returns 0 and window_device() in EDL returns a nice hex value.

The following call causes ENIGMA to crash even though I use error checking.  ???

Code: [Select]
export double createQuad()
{
if(!d3dDevice)
return 1000;

int nNumVerts=4;

if(FAILED(d3dDevice->CreateVertexBuffer((nNumVerts)*sizeof(D3DVERTEX),D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,D3DFVF_XYZRHW|D3DFVF_DIFFUSE,D3DPOOL_DEFAULT,&pVertexObjectQuad,NULL)));
return 1;

return 0;
}

How can this possibly cause a crash?

If it fails it should just return '1' to the calling function.  ???

This is wierd as...

On GM:S, if I leave out the call to get window_device() (to force an error) then create_quad will return 1 as expected. If I do the same with ENIGMA it shits itself and crashes.

So, the problem isn't related to window_device anymore. It is to do with ENIGMA crashing if a error checked directx call happens.

I just can understand why an error handled call should crash anything.  ???

Possibly something to do with my DLL built on MSVC?

I have also checked that we don't have a DX9 (subversion) conflict. My DLL is using d3dx9_43 (June 2010 SDK). From what I can see, ENIGMA is built on the same version of DX9.

Only difference now that I can see is MinGW & MSVC.
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 03, 2014, 07:16:02 am
I would guess it crashes becaused3dDevice is not initialized to 0. Also, passing a garbage pointer is hard to detect. But I don't know for sure --the pointer seems to be valid, so maybe the DirectX ENIGMA users have an idea?
Title: Re: [Solved] Adding a new function
Post by: Goombert on October 03, 2014, 07:38:20 am
Sorlok is right, it's a garbage pointer and you are checking if its null, its obviously not null because it's a garbage pointer, and then you try to access it inside the FAILED() call which leads to a segfault. Run the game in debug mode to build with debug symbols, then open git-bash and type "gdb path/to/temp/file/from/lgmsconsole" and hit enter, then when it loads the temp file LGM outputted with debug symbols just type "run" and hit enter and it should launch and then crash giving you a stack trace. Then you type "bt" for the backtrace and it will tell you the exact file and line number it crashed in, though idk if it will get the symbols from the DLL properly or not but it should, if not build a debug version of the dll.

Anyway to prove my point, remove the FAILED() macro and it should still crash. It has nothing to do with DirectX, it is still an issue in the variant.
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 03, 2014, 09:26:34 pm
All the variant is doing is wrapping the pointer and then passing it back; I've confirmed that it works for simple new'd data. It would have to be something slightly more complicated, I think, to cause the invalid pointer to be saved.

Can you post a branch and test game, so that I can run it through GDB?
Title: Re: [Solved] Adding a new function
Post by: Goombert on October 03, 2014, 11:07:46 pm
Ok my apologies sorlok, I have run some tests and it appears your code is working fine.

WINDOWSmain.h
Code: (cpp) [Select]
namespace enigma_user
{
void test_draw_clear(void* d3ddev);
void* window_device();
unsigned long long window_handle();
int sleep(int millis);
}

graphics_bridge.cpp
Code: (cpp) [Select]
void* window_device() {
  return (void*)d3dmgr->device;
}

void test_draw_clear(void* d3ddev) {
  IDirect3DDevice9* dev = (IDirect3DDevice9*)d3ddev;
  dev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(255, 0, 0, 255), 0, 0);
}

Object Draw Event
Code: (EDL) [Select]
test_draw_clear(window_device());

Works perfectly as expected and clears the background color to red. It must be an issue with the dll functions then.
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 03, 2014, 11:23:57 pm
Glad the pointer passing is working. Once you figure out the DLL issue, let me know  ---we really need to have a discussion about the "right" way to store pointers in variants (since my solution is a bit hacky).
Title: Re: [Solved] Adding a new function
Post by: Goombert on October 03, 2014, 11:30:39 pm
Oh boy sorlok, I haven't really worked with dll's that much so I don't know how to reproduce and test what he's testing. In fact I don't think I've ever written a dll before, except changes to the compiler which make compileEGMf, but other than that I've never made my own dll's before. Additionally Josh would be the best person to talk about variant, I don't think I would be able to fully understand the implications.
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 03, 2014, 11:39:26 pm
My knowledge of DLLs is also limited. I guess we'll need lonewolf to post some sample project & branch.

I'll talk to Josh about this once there's a clear need for pointers in variants. Right now it seems like we'll definitely need to look at this for external library initialization, but maybe there's a better way to chain the calls and avoid variants entirely? After all, normal ENIGMA scripts shouldn't really be playing around with pointers.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 04, 2014, 05:27:03 pm
Still in Sydney at the moment so don't have access to any code right now.

Having said that, the exact same DLL is working 100% in GM:S.

Even if I skip the init to force a null pointer for the device, in the quad crate call, GM:S returns 1 for failed call (as expected) but ENIGMA crashes instantly.
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 04, 2014, 05:54:34 pm
Still in Sydney at the moment so don't have access to any code right now.

Having said that, the exact same DLL is working 100% in GM:S.

Even if I skip the init to force a null pointer for the device, in the quad crate call, GM:S returns 1 for failed call (as expected) but ENIGMA crashes instantly.

Yes, but that's probably because your pointer is initially in a garbage state anyway (because you never set it to anything).

Anyway, it's much better to wait until we get an actual test case; I don't think we'll be able to solve this until Robert and I actually have something concrete to work with.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 04, 2014, 06:01:05 pm
Yep, for sure.

Still confused though. Even if it were a garbage pointer, the error checking would return a D3DERR* message, not simply crash the app.

I am extremely pedantic when error checking, as I never want to release buggy code to the public.

But, for sure, ill send over the DLL and source when I get back to civilisation. :)
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 04, 2014, 06:12:15 pm
Just think of it this way:

Code: [Select]
D3DWhatever* something = 0xFF00FF;
Give this garbage pointer, how can you *possibly* know it's invalid? In C++, it just points to a memory location, and the runtime just assumes that you point to one that represents an object, or NULL.

Now, D3D *could* maintain a list of all known D3DWhatever pointers somewhere global, and check this every single time it's given a pointer. But that's costly, and it only helps very obscure cases like this one.

Valgrind might be able to detect this, if the memory being pointed to is uninitialized or something like that. But even then, it's kind of a gray area.

This is one very good reason why you should always initialized your pointers to NULL; it allows the runtime to detect when a pointer is definitely invalid.
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 04, 2014, 06:18:10 pm
Just think of it this way:

Code: [Select]
D3DWhatever* something = 0xFF00FF;
Give this garbage pointer, how can you *possibly* know it's invalid? In C++, it just points to a memory location, and the runtime just assumes that you point to one that represents an object, or NULL.

Now, D3D *could* maintain a list of all known D3DWhatever pointers somewhere global, and check this every single time it's given a pointer. But that's costly, and it only helps very obscure cases like this one.

Valgrind might be able to detect this, if the memory being pointed to is uninitialized or something like that. But even then, it's kind of a gray area.

This is one very good reason why you should always initialized your pointers to NULL; it allows the runtime to detect when a pointer is definitely invalid.

First things first, I always initialise pointers to 0 (as I have done in my DLL)

Secondly even if your pointer is some random value, this is what the D3D calls return code is for. It will return an error upon failure regardless of what caused the error (invalid devices etc..).

If the device handle is some random garbage, the call will simply return an error (not crash) unless the error is disregarded and program flow continues.
Title: Re: [Solved] Adding a new function
Post by: sorlok_reaves on October 04, 2014, 06:26:28 pm
I'm not so familiar with DirectX, so you're probably right. Anyway, if it's crashing on NULL then something is definitely wrong.
Title: Re: [Solved] Adding a new function
Post by: Goombert on October 04, 2014, 07:12:40 pm
Quote from: lonewolf
the error checking would return a D3DERR* message, not simply crash the app.
No it would not, because the FAILED() macro does not check for garbage pointers, it doesn't check for pointers at all in fact.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms693474%28v=vs.85%29.aspx

Code: (cpp) [Select]
#define FAILED(hr) (((HRESULT)(hr)) < 0)
The following would crash.
Code: (cpp) [Select]
if(FAILED(d3dDevice->CreateVertexBuffer((nNumVerts)*sizeof(D3DVERTEX),D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,D3DFVF_XYZRHW|D3DFVF_DIFFUSE,D3DPOOL_DEFAULT,&pVertexObjectQuad,NULL)));
Even if you took it out of the macro, before it even enters the function, that's GCC/MinGW/C++ not DirectX failing.
Code: (cpp) [Select]
d3dDevice->CreateVertexBuffer((nNumVerts)*sizeof(D3DVERTEX),D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,D3DFVF_XYZRHW|D3DFVF_DIFFUSE,D3DPOOL_DEFAULT,&pVertexObjectQuad,NULL);
Title: Re: [Solved] Adding a new function
Post by: Darkstar2 on October 04, 2014, 08:37:15 pm

I am extremely pedantic when error checking, as I never want to release buggy code to the public.

Yeah you just threw out the window any chance you have at working for ANY software developing company, NOBODY would hire you ! LOL.  ;D   God forbid if software companies had people like that, consumers would have better software but turn around times would be exponentially higher and shite would not be released fast enough (or ever) :D
Though you shouldn't worry about that with ENIGMA, nobody is going to crucify you for finding bugs in your free extension, considering the said product is not exactly bug free to begin with LOL.

Cheers

Quote
But, for sure, ill send over the DLL and source when I get back to civilisation. :)

We're looking forward to your plugin, it would be great, assuming you don't get bitten by scorpions or swallowed by crocodiles, all good ! Later :D
Title: Re: [Solved] Adding a new function
Post by: lonewolff on October 05, 2014, 04:17:10 am
Actually had a scorpion in my back yard the other day when I was moving some bricks.

Yet to see a crocodile in my back yard yet.

Although, I do see kangaroos here in a daily basis :)
Title: Re: [Solved] Adding a new function
Post by: Darkstar2 on October 05, 2014, 01:07:57 pm
Actually had a scorpion in my back yard the other day when I was moving some bricks.

Was it that Scorpion named Samuel ? LOL!

Quote
Yet to see a crocodile in my back yard yet.

I rather see crocs in my back yard than snakes :D

Anyhow looks like you have quite a challenge here with your plugin ..... I'm wondering if the crash problem doesn't come from something else unrelated, maybe something major that will be discovered from this who knows.........hopefully you can find a way to get this done, that will open the doors to other plugins too...