Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
DLL return values, MANY CRASH error! - SOLVED #425465
07/05/13 17:25
07/05/13 17:25
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Hello friends!.
I created a dll made ​​in C + + to return values ​​that were surveyed in a database SQLITE3!

At first everything works correctly, BUT , when the database starts to earn enough database tables start getting bigger is that my real problem starts! The operation is totally unstable!

Suddenly I get an crash error.
These errors happen when I need to receive the data.
But not always. Sometimes it works fine and others it can generate a crash error, which I can not identify.

But I managed to identify these occasional errors always happen when I use search functions of data. When I need to get a large number data is then subject to severe receiving a crash error.

could you give me tips so I can STABILISE my function?

Sample my DLL and LiteC Script:

C++
Code:
//Receive data from rows and columns of the DataBase
...
DLLFUNC char* sqlite__select(int r, int c)
{
 //return char value on rows [r] and Column [c]
  return ((char*)result[r][c].c_str());
        
}
...



LiteC, Receive Many data.

Code:
void test_select()
{

int rows = sqlite_rows(); //Total de rows (sample 100 rows)

for(ping = 0; ping < rows; ping ++)
{
//ID			
printf("%s",sqlite_select(ping,0)); //return 0..1..2..3..4..n
//test0
printf("%s",sqlite_select(ping,1)); //return 0..1..2..3..4..n
//test1
printf("%s",sqlite_select(ping,3)); //return 0..1..2..3..4..n
.... test100

}



Can happen or not returning a crash error. (T.T)




Last edited by NeoNeper; 07/05/13 18:45.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: DLL return values, MANY CRASH error! [Re: NeoNeper] #425466
07/05/13 17:55
07/05/13 17:55
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
I could imagine that returning the c_str() is not a good idea. Maybe you pass a char* buffer instead, in which you write the result?

Code:
DLLFUNC char* sqlite__select(char* buffer, int r, int c)
{
    if (buffer != NULL)
        strcpy(buffer, result[r][c].c_str());
        
    return buffer;
}



Code:
void test_select ()
{
    int rows = sqlite_rows();
    
    char buffer [256];
    
    int ping;
    for (ping = 0; ping < rows; ping++)
    {
        printf("%s", sqlite_select(buffer, ping, 0));
        printf("%s", sqlite_select(buffer, ping, 1));
        printf("%s", sqlite_select(buffer, ping, 3));
    }
}


Re: DLL return values, MANY CRASH error! [Re: HeelX] #425467
07/05/13 18:19
07/05/13 18:19
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
ooh THAT AND A really good idea.
Testing will!


Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: DLL return values, MANY CRASH error! [Re: NeoNeper] #425468
07/05/13 18:59
07/05/13 18:59
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
seem to work!
tested many again my game, and I had no more problems! (^.^) Tankx HeelX.

If you have a few more important tips for working with DLL, please teach for me.
(^.~)


Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: DLL return values, MANY CRASH error! [Re: NeoNeper] #425470
07/05/13 20:31
07/05/13 20:31
Joined: May 2013
Posts: 23
Somewhere
W
Wiseguy Offline
Newbie
Wiseguy  Offline
Newbie
W

Joined: May 2013
Posts: 23
Somewhere
Originally Posted By: NeoNeper
If you have a few more important tips for working with DLL, please teach for me.
(^.~)

I have told you about the problem with auto variables multiple times before in this thread, but you chose to ignore it. And I don't doubt that you will do the same mistake again in the near future.

Important tip: PLEASE get familiar with C++ before doing anything else. That your program crashed was very fortunate, because it's an easy way to track down undefined behaviour, but you are not guaranteed to be that lucky every time.

Also, in a similar vein, DON'T use old C-Style casts! They are too broad and you lose an awful lot of control when using them. And don't cast away constness if you don't need to, and if you absolutely need to, use const_cast<>().


His words are wise, his face is beard.
Re: DLL return values, MANY CRASH error! [Re: Wiseguy] #425580
07/08/13 17:57
07/08/13 17:57
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
tanks Wiseguy.
Some times I have difficulty understanding, for not mastering the English language fluently.

I have trouble with C + +, but I'm slowly learning, with your help and support materials. I am so grateful to this community.

I have done great things using LITEC along with C + +!
The LITEC became a door for me to enter this world of programming games and consequently for me to learn new programming languages!.


Last edited by NeoNeper; 07/08/13 18:00.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: DLL return values, MANY CRASH error! [Re: NeoNeper] #425585
07/08/13 19:06
07/08/13 19:06
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
NeoNeper, there are just a few things to remind when working with C++ DLLs and Gamestudio. Most important is the fact that you have to use the _VAR() macro to turn numeric values into the var-representation, when passing to Gamestudio functions. The same goes for the other way round, please use always the _INT() and _FLOAT() macros to convert vars into numeric values.

Beside that, there are no special advices we can give you, since all other advices might be focused on C++ and for that, you can simply buy a book that handles that better than we can.

Re: DLL return values, MANY CRASH error! [Re: HeelX] #425764
07/10/13 16:04
07/10/13 16:04
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Tanks HeelX (^.^).


Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1