Skip to content

Segmentation Fault #10

Closed
Closed
@lostjared

Description

@lostjared

acidcam: input[/home/jared/Videos/freddy.mov] output[fredtest.mov] width[592] height[448] fps[29.92] length[37.03 seconds] format[MPEG-4 (Quicktime)]

Filters to Apply:
Plugin
acidcam: Working frame: [0/1108] - 0% Size: 0 MB

Thread 1 "acidcam" received signal SIGSEGV, Segmentation fault.
0x00007fffcd3a1bcf in PyErr_SetObject () from /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
(gdb) backtrace
#0 0x00007fffcd3a1bcf in PyErr_SetObject () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#1 0x00007fffcd3a224f in PyErr_SetString () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#2 0x00007fffcc51c93e in _wrap_metacall () at /usr/local/lib/_py_port.so
#3 0x00007fffcd4549eb in _PyCFunction_FastCallDict () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#4 0x00007fffcd3bce0c in () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#5 0x00007fffcd3c3092 in _PyEval_EvalFrameDefault () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#6 0x00007fffcd3bc63f in () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#7 0x00007fffcd3bd0fe in PyEval_EvalCodeEx () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#8 0x00007fffcd47d782 in () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#9 0x00007fffcd4aa2d8 in PyObject_Call () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#10 0x00007fffcd90386e in function_py_interface_invoke () at /usr/local/lib/libpy_loader.so
#11 0x00007ffff65d398b in metacallt () at /usr/local/lib/libmetacall.so
#12 0x000055555556680e in plugin_callback(cv::Mat&) (frame=...) at acidcam-cli-main.cpp:138
#13 0x00007ffff784bf22 in ac::CallFilter(int, cv::Mat&) (index=, frame=...) at ac-filter1.cpp:146
#14 0x0000555555563eed in cmd::AC_Program::run() (this=0x55555576e720 ) at acidcam-cli.cpp:441
#15 0x000055555555f3dd in main(int, char**) (argc=9, argv=0x7fffffffdea8) at acidcam-cli-main.cpp:700
(gdb)

if I comment out val = metacall('matrix_getpixel',matrix, i, z) it does not crash.
if this is something on my side I apologize for bothering.

Python code:

import random, sys
sys.path.append("/usr/local/lib")
from metacall import metacall

def array_size(width: int, height: int) -> int:
global screen_width
global screen_height
global pitch_value
screen_width = width
screen_height = height
pitch_value = width*3
return 0

def filter(matrix):
for z in range(0, screen_height-1):
for i in range(0, screen_width-1):
val = metacall('matrix_getpixel',matrix, i, z)
metacall('matrix_setpixel',matrix, i, z, 0)
return 0

C++ code:

#if METACALL_ENABLED == 1

void init_metacall();
void *matrix_SetPixel(void *args[]);
void *matrix_GetPixel(void *args[]);

void init_metacall() {
metacall_register("matrix_setpixel", matrix_SetPixel, METACALL_PTR,4, METACALL_PTR, METACALL_INT, METACALL_INT, METACALL_INT);
metacall_register("matrix_getpixel", matrix_GetPixel, METACALL_ARRAY, 3, METACALL_PTR, METACALL_INT, METACALL_INT);

//metcall_register("matrix_setpixel_rgb", matrix_SetPixelRGB, METACALL_PTR, 7, METACALL_PTR, METACALL_INT, METACALL_INT, METACALL_INT, METACALL_INT, METACALL_INT)
//metacall_register("matrix_getpixel", matrix_GetPixel, METACALL_INT,3, METACALL_PTR, METACALL_INT, METACALL_INT);

}

void *matrix_SetPixel(void args[]) {
cv::Mat type = (cv::Mat)metacall_value_to_ptr(args[0]);
int x = metacall_value_to_int(args[1]);
int y = metacall_value_to_int(args[2]);
int color_value = metacall_value_to_int(args[3]);
const unsigned char bgr = (const unsigned char)&color_value;
type->atcv::Vec3b(y, x) = cv::Vec3b(bgr[0], bgr[1], bgr[2]);
return metacall_value_create_ptr((void
)type);
}

void *matrix_GetPixel(void *args[]) {
cv::Mat type = (cv::Mat)metacall_value_to_ptr(args[0]);
int x = metacall_value_to_long(args[1]);
int y = metacall_value_to_long(args[2]);
cv::Vec3b color_v = type->atcv::Vec3b(y, x);
void *array[] = {metacall_value_create_char(color_v[0]), metacall_value_create_char(color_v[1]),metacall_value_create_char(color_v[2])};
return metacall_value_create_array((const void **)array, sizeof(array)/sizeof(array[0]));
}

#endif

For init stuff i have:

in main function:
#if METACALL_ENABLED == 1
metacall_log_stdio_type log_stdio = { stdout };
metacall_log(METACALL_LOG_STDIO, (void *)&log_stdio);
metacall_initialize();
#endif

in Program class

bool AC_Program::loadPlugin(const std::string &s) {
    if(s.find(".py") != std::string::npos) {

#if METACALL_ENABLED == 1
std::string dir = s;
std::string path = dir.substr(0, dir.rfind("/"));
std::string script_name=s.substr(s.rfind("/")+1, s.length());
std::cout << "Attempting to load: " << script_name << "\n";
const char * py_scripts[] = {
script_name.c_str(),
};
if (metacall_load_from_file("py", py_scripts, sizeof(py_scripts) / sizeof(py_scripts[0]), NULL) == 0) {
return true;
}
#else
std::cerr << "Error Python Not Enabled...\n";
exit(EXIT_FAILURE);
#endif
} else {
library = dlopen(s.c_str(), RTLD_LAZY);
if(library == NULL)
return false;

        void *addr = dlsym(library, "filter");
        const char *err = dlerror();
        if(err) {
            std::cerr << "Could not locate function: filter in " << s << "\n";
            return false;
        }
        plugin = reinterpret_cast<plugin_filter>(addr);
    }
    return false;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions