Forum

Author Topic: Bad allocation error catch.  (Read 1984 times)

jrjdavidson

  • Newbie
  • *
  • Posts: 21
    • View Profile
Bad allocation error catch.
« on: June 10, 2024, 10:05:31 PM »
Kia ora,

we've setup a way to automatically setup network tasks, using the agisoft scripts on github as inspiration. It works great, however every now and then a project gets stuck on a bad allocation error loop. Trawling the forum indicates this is a RAM issue. I've tried all the tips I've found on here but haven't been able to solve it so far.

I have a couple of questions:
1) can you confirm that the bad allocation error is always RAM issue? Apparently our machine does not max out the RAM when the issue occurs.
2) is there a way to set up an exception catch for errors like this? I thought we could split the chunk if this type of error was thrown, if only we write a try/except pattern for this type of error.

Thank you!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15086
    • View Profile
Re: Bad allocation error catch.
« Reply #1 on: June 11, 2024, 07:55:34 PM »
Hello jrjdavidson,

In most cases "bad allocation" means insufficient RAM (could be also insufficient free RAM to allocate certain amount of memory).

I think you can use try/except approach for such problems, providing that there is no system service that terminates the process which tries to allocate RAM above certain threshold.
Best regards,
Alexey Pasumansky,
Agisoft LLC

jrjdavidson

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Bad allocation error catch.
« Reply #2 on: June 12, 2024, 11:45:31 AM »
ok, thanks.

For a network task, how would i try to catch an error like this? should i create a something like
Code: [Select]
#previous code
task = Metashape.Tasks.BuildPointCloud()
tasks.append(task)

#new code
task = Metashape.Tasks.RunScript()
task.code='''
import Metashape
doc = Metashape.Document()
doc.open("path\to\project.psx", ignore_lock = True)
chunk = doc.chunk
try:
    chunk.buildPointCloud()
except Metashape.BadAllocationError: #just guessing how to catch errors
    #code to split chunks here
'''
tasks.append(task)