Jump to content

Stackoverflow in function (Slot Machine System)


Recommended Posts

Hey guys, i found a system released in owsap's github. I implemented it, but when i press the start button, my game crashes and my vdi says "Stackoverflow detected..."

 

Here is the function 

bool CHARACTER::StartSlotMachine(uint8_t bBet)
{
	if (!IsPC())
		return false;

	if (!GetDesc())
		return false;

	if (!CanWarp())
		return false;

	if (!m_bSlotMachineOpen)
		return false;

	if (m_pkSlotMachineEvent)
	{
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("[Slot Machine] The machine is already running."));
		return false;
	}

	if (bBet > SlotMachineBetMap.size() || bBet < 1)
		bBet = 1;

	int64_t iPrice = SlotMachineBetMap[bBet];
	if (GetGold() < iPrice)
	{
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("[Slot Machine] You don't have enough money to bet."));
		return false;
	}

	uint8_t iSlotMachineMltiplier = quest::CQuestManager::instance().GetEventFlag("slot_machine_multiplier");
	if (iSlotMachineMltiplier > 0)
		bBet += iSlotMachineMltiplier;

	uint8_t iSlotMachineReels = quest::CQuestManager::instance().GetEventFlag("slot_machine_reels");
	for (uint8_t bSlot = 0; bSlot < ESlotMachine::MAX_SLOT_MACHINE_SLOTS; ++bSlot)
	{
		std::random_device rd;
		std::mt19937 mt(rd());
		std::uniform_real_distribution<> dist(1, (iSlotMachineReels > 0 ? iSlotMachineReels : ESlotMachine::MAX_SLOT_MACHINE_REELS));
		m_bSlotMachineReel[bSlot] = static_cast<uint8_t>(dist(mt));
	}

 

 

Can someone help me?

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Honorable Member

Here, use int for the loop and you can also use the default number function to randomize the numbers.

	for (int bSlot = 0; bSlot < ESlotMachine::MAX_SLOT_MACHINE_SLOTS; ++bSlot)
	{
		m_bSlotMachineReel[bSlot] = number(1, (iSlotMachineReels > 0 ? iSlotMachineReels : ESlotMachine::MAX_SLOT_MACHINE_REELS));
	}

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.