Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate memory error. #103

Open
jekoie opened this issue Dec 9, 2023 · 6 comments
Open

Allocate memory error. #103

jekoie opened this issue Dec 9, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@jekoie
Copy link

jekoie commented Dec 9, 2023

My gerber file see bellow

G04 Ucamco ex. 4.6.4: Simple contour*
%FSLAX25Y25*%
%MOIN*%
%ADD10C,0.010*%
G36*
X200000Y300000D02*
G01*
X700000D01*
Y100000D01*
X1100000Y500000D01*
X700000Y900000D01*
Y700000D01*
X200000D01*
Y300000D01*
G37*
M02*

code sample

from pygerber.gerberx3.api import (
      ColorScheme,
      Rasterized2DLayer,
      Rasterized2DLayerParams,
)

# Path to Gerber source file.
source_path = "./example/example_simple_contour.gbr"

Rasterized2DLayer(
      options=Rasterized2DLayerParams(
            source_path=source_path,
            colors=ColorScheme.COPPER_ALPHA,
      ),
).render().save("output.png")

console error

WARNING:root:Detected use of imperial units. Using metric units is recommended. Imperial units will be deprecated in future. (See 4.2.1 in Gerber Layer Format Specification)
Traceback (most recent call last):
  File "c:/Users/jekoi/Desktop/t/main.py", line 10, in <module>
    Rasterized2DLayer(
  File "c:\Users\jekoi\Desktop\t\pygerber\gerberx3\api\_layers.py", line 173, in render
    result_handle = draw_commands.draw()
  File "c:\Users\jekoi\Desktop\t\pygerber\backend\abstract\draw_commands_handle.py", line 21, in draw
    return self.backend.draw(self.draw_commands)
  File "c:\Users\jekoi\Desktop\t\pygerber\backend\abstract\backend_cls.py", line 97, in draw
    self._post_drawing_hook()
  File "c:\Users\jekoi\Desktop\t\pygerber\backend\rasterized_2d\backend_cls.py", line 165, in _post_drawing_hook
    self._replace_image_colors()
  File "c:\Users\jekoi\Desktop\t\pygerber\backend\rasterized_2d\backend_cls.py", line 181, in _replace_image_colors
    rgba_img[np_img == gray_value] = rgba
numpy.core._exceptions.MemoryError: Unable to allocate 240. MiB for an array with shape (63007000,) and data type int32     
PS C:\Users\jekoi\Desktop\t> 

Another, I notice the pcb-tools nobody maintained, and you re-new a new gerber project.I use part of pcb-tools projects to draw PyQt/PySide graph.But I don't now how to use your code draw PyQt/PySdie shape.I had read small part of your code,but I not found the code that draw the shape(like cairo).

@jekoie jekoie added the bug Something isn't working label Dec 9, 2023
@Argmaster
Copy link
Owner

It looks like allocation error caused by insufficient availability of resources at runtime? How much unused RAM do you have while running this code?
However, even if it is caused by insufficient memory availability It might be a good idea to optimize color replacement memory requirements.

@Argmaster
Copy link
Owner

To add new drawing backend, you should be generally interested in two places:

Actual draw operations are performed in DrawCommand derived classes, eg. here

@Argmaster Argmaster self-assigned this Dec 9, 2023
@jekoie
Copy link
Author

jekoie commented Dec 9, 2023

the unused memory is about 2-3G,the resource is sufficient.

@Argmaster
Copy link
Owner

Argmaster commented Dec 11, 2023

I will need more of your help with reproducing this issue, as I am not able to reproduce this issue within my development evrionment. Could you please provide contents of pip freeze, OS, CPU, RAM (size) and full Python version (python -VV), so I will have a better idea about your environment?

Peak memory usage for your Gerber file is around 1.6GB on my system, therefore I am still considering this a possible cause, thus OS might have refused allocating continuous block of 240MiB

Please try using lower DPI setting and verify if issue occurs also to smaller DPIs.

@Argmaster
Copy link
Owner

@jekoie please let me know if you are willing to help with reproduction.

@Argmaster Argmaster added this to the Distant Future milestone Jan 17, 2024
@Argmaster
Copy link
Owner

Pinging @jekoie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Research
Development

No branches or pull requests

2 participants