Bad allocation error on client->authenticateDevice()


I’m pleased to report I’ve made substantial progress. I’ve got a rudimentary Nakama implementation running in C++. It can create and join matches and run a super simple player interaction.

Now I need to embed these functions into a another SDK I want to work with and then I can begin making my application!

The trouble is when I call client->authenticateDevice() from within my other SDK I get back an error back, “exception: bad allocation.”

I’ve raised a ticket with the other SDK support group. I’ve even sent them my project and asked them to have a look at my code. They have confirmed that I’ve implemented their material correctly and that what I’m trying to do should work.

They suggested “stepping into the Nakama code if to see if it’s actually an issue within Nakama trying to access something that hasn’t been created yet.”

I’m not sure how Nakama could be trying to access something that hasn’t been created yet since I’m using an implementation that works on it’s own. But clearly something is different. The question is how to find out what?

I’m pretty confident I have all my linker settings, includes, and configuration set up properly. I can build without errors, and some Nakama functions do run. I can build the client and tick.

Below is the code block pertaining to Nakama.

Here is the output:

The IDE reports a little more detail:

If I give values for “userName” and “create” instead of using nullopt, I get something slightly different.

Do you have any thoughts about what might cause authenticateDevice to return errors like this? Any suggestions on how to go about debugging an issue like this?

Or, perhaps, could Heroic Labs provide a pbd file for nakama-cppd.dll? At least then I could step into the function myself and see what’s going on.

I suppose I could try to build the source code locally and add print statements to authenticateDevice() or make a .pbd file, but that sounds daunting and has lots of dubious possible outcomes.

Thank you so much for any input.

Hey @Mehoo I’d recommend using a native debugging program like lldb or gdb to identify the line of code causing the issue.

What I’d so with lldb (I’m sure gdb has analogous commands) would be:

  • lldb <./relative_path_to_exe>
  • break set -E c++
  • run

And you can use the up and down to traverse the stack.

Thank you for the feedback, but I wasn’t able to use these suggestions. I had some serious difficulty getting lldb or gdb to work with Visual Studio and gave up on that. I was able to get gdb running as a standalone tool.

However, I’m trying to build Nakama into a custom plugin for a closed-source app. Since I don’t have a debug build of the main app, I can’t hook it up to gdb to tell me what’s going on when that app calls my code.

I thought I might have a little more flexibility with XCODE since lldb is built into that. I’m pretty sure I followed the instructions. But I wasn’t able to get Nakama to build build on my Mac.

That leaves me little choice but to try building the source myself and including a .pdb file. However, following the instructions, I wasn’t able to get the Source to build either.

So now I’m completely stuck. I’m hoping I can get the source to build some day. I feel like that will allow me to get the most information about why things are breaking when I try to apply Nakama to my end-goal.

Thank you for any assistance!

I was able to build the source successfully and debug this.

The problem appears to be with the optional-lite library. This library requires special consideration. In the github description it says “If available, std::optional is used.

While this might seem to be convenient, this feature breaks Nakama functions with optional parameters in environments where std::optional is present.

For example, an environment with my other SDK. The result is that authenticateDevice() calls std::optional instead of nonstd::optional to process optional parameters. This leads to problems when trying to assemble those parameters into a POST request to the server.

Optional-lite documentation mentions a way of over-riding this feature. But I can’t really make sense of what it’s saying. Hopefully someone here can provide some insight into how to run Nakama in environments where std::optional is available.

I’ll make another post about that, since the question is getting buried here.

Solution here: