yourWaifu / sleepy-discord

C++ library for the Discord chat client. Please use Rust for new bots
https://yourWaifu.github.io/sleepy-discord/
MIT License
707 stars 95 forks source link

Leveldb integration Segmentation fault (core dumped) #99

Closed ghost closed 6 years ago

ghost commented 6 years ago

I tried to integrate Leveldb, creating the database works but trying my test command crashes the server.

if (message.startsWith(prefix + " leveldbtest"))
{
    std::string value;
    leveldb::Status s = ldb->Get(leveldb::ReadOptions(), "key1", &value);
    if (s.ok()) s = ldb->Put(leveldb::WriteOptions(), "key2", value);
    if (s.ok()) s = ldb->Delete(leveldb::WriteOptions(), "key1");
}
yourWaifu commented 6 years ago

Umm I'm not sure what the above code even does. The only thing made by me is the message.startsWith. I don't think this is actually an issue with my library.

ghost commented 6 years ago

sry if this is the wrong place to post it, im just confused that it crashes.I thought you might have an idea, the leveldb sample code works for me when i build it.

here's my full code gist( it looks bad that's why i didn't showed all. ) https://gist.github.com/Kaugummis/258483cddd2f4fad1c5c50247eb23217

Leveldb doc https://github.com/google/leveldb/blob/master/doc/index.md

I tried mysql too but it didn't worked with the same crash reason. I just want database support for my bot.

any ideas?

yourWaifu commented 6 years ago

Well if you using visual studio or a debugger try looking at the values like ldb and see if it points to a valid value. Also where in the code is it crashing? Can you get the call stack of when the crash happens? Those are the type of questions you should be asking yourself in these types of situations.

yourWaifu commented 6 years ago

also, Maybe there was an issue here?

leveldb::Status dbstatus = leveldb::DB::Open

call dbstatus.ok() to see if maybe there was an issue there.

ghost commented 6 years ago

sorry again (shouldn't have posted this as an issue), thanks for your help i figured it out what it was.It works now (very common mistake!).

offtopic i heard you have a discord for this library, i can't find the invite link would be nice if you posted it.

yourWaifu commented 6 years ago

Where did you heard that? Well, I don't have one. You can always reach me on Discord api. https://discord.gg/discord-api

ghost commented 6 years ago

oh well i just misread your sentence on how to make a basic text bot.