std:bad_alloc

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
BruceTheGoose
Citizen
Posts: 76
Joined: Sat Sep 20, 2014 2:54 pm

std:bad_alloc

Post by BruceTheGoose »

I suspected a memory leak in my game so I let it run for about an hour and I finally got a crash message ...
IMG_1079 (2).PNG
IMG_1079 (2).PNG (385.51 KiB) Viewed 3735 times
If anyone can provide an explanation for this error that would be awesome.
"I don't know."
MrFariator
Party member
Posts: 511
Joined: Wed Oct 05, 2016 11:53 am

Re: std:bad_alloc

Post by MrFariator »

Can you show code?
User avatar
BruceTheGoose
Citizen
Posts: 76
Joined: Sat Sep 20, 2014 2:54 pm

Re: std:bad_alloc

Post by BruceTheGoose »

MrFariator wrote: Sun Jan 06, 2019 4:09 am Can you show code?
Here are the relevant code snippets:

I have a scroll frame object with a function that gets all of the visible objects :

Code: Select all

function Scroll:getVisibleObjects()
  local visible = {}

  for i = 1, #self.content.objects do
    if(self:checkCollision(self.content.objects[i])) then
      visible[#visible + 1] = i
    end
  end
  return visible
end
This function is called in the scroll frame's update function :

Code: Select all

function Scroll:update(dt, scrolling)

  self:handleScrollbar()

  if(self.content.height > self.height) then

    self:handleScrolling(dt)

    self.touched = self:getTouch()

    if(self.touched) then
      self:handleTouch(dt, scrolling)
    else
      self:handleRelease(dt)
    end
  end
  
  self.visible = self:getVisibleObjects()
  self.content:update(dt, self.visible)
end
This is the draw method for a button :

Code: Select all

function Button:draw()

  if(self.visible) then
    lg.setColor(0, 0, 0, self.shadowIntensity)
    lg.draw(Loader.gfx["boxshadow"], self.x + self.shadowOffsetX, self.y + self.shadowOffsetY, 0, self.shadowScaleX, self.shadowScaleY)

    lg.setColor(self.colorHover[1], self.colorHover[2], self.colorHover[3], self.alpha)
    lg.rectangle("fill", self.x, self.y + self.height * 0.55, self.width, self.height * 0.5, self.roundness, self.roundness) -- Line 97
    
    ......
"I don't know."
MrFariator
Party member
Posts: 511
Joined: Wed Oct 05, 2016 11:53 am

Re: std:bad_alloc

Post by MrFariator »

Can't really spot anything that could be at fault in those snippets, because it doesn't really show the internal workings of your code. However, what does

Code: Select all

Loader.gfx["boxshadow"]
do? Is that the line 97 the game errors on?
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: std:bad_alloc

Post by slime »

std::bad_alloc is just a generic "out of memory" message – LÖVE's internal C++ code tries to allocate some memory but either the program has already run out of memory by that point, or you're making it allocate a massive amount of memory due to the arguments you pass in to the function that's outputting that error.

It's probably going to be really hard to see where your memory leak is coming from without a .love file.
Post Reply

Who is online

Users browsing this forum: No registered users and 91 guests