arrayfire icon indicating copy to clipboard operation
arrayfire copied to clipboard

graphics window creation excecption :this->mMainWindow._Mypair._Myval2 was nullptr.

Open coderboyisongithub opened this issue 3 years ago • 1 comments

What is this error?I am using your code from example on github page.

             static const float h_kernel[] = { 1, 1, 1, 1, 0, 1, 1, 1, 1 };
	static const af::array kernel(3, 3, h_kernel, afHost);
            af::array state = (af::randu(128, 128, f32) > 0.5); // Init state
	const static int width = 512, height = 512;
	af::Window myWindow("2D plot example title");///excecption!! (this->mMainWindow._Mypair._Myval2 was nullptr.)
	
	while (!myWindow.close()) 
	{
		af::array nHood = convolve(state, kernel); // Obtain neighbors
		af::array C0 = (nHood == 2);  // Generate conditions for life
		af::array C1 = (nHood == 3);
		state = state * C0 + C1;  // Update state
		myWindow.image(state);    // Display
	}

coderboyisongithub avatar Jul 07 '22 06:07 coderboyisongithub


#include <arrayfire.h>
#include <iostream>

int main() {
    af::info();  // Ensure ArrayFire is properly initialized

    // Initialize the 3x3 convolution kernel
    static const float h_kernel[] = { 1, 1, 1, 1, 0, 1, 1, 1, 1 };
    af::array kernel(3, 3, h_kernel, afHost);

    // Initialize random state
    af::array state = (af::randu(128, 128, f32) > 0.5); 

    // Create a window for visualization
    af::Window myWindow(512, 512, "Game of Life - ArrayFire");

    // Main loop
    while (!myWindow.close()) {
        af::array nHood = af::convolve(state, kernel); // Compute neighbors
        af::array C0 = (nHood == 2);  // Condition for life
        af::array C1 = (nHood == 3);
        state = state * C0 + C1;  // Update state
        
        myWindow.image(state);    // Display
    }

    return 0;
}

ljluestc avatar Feb 10 '25 01:02 ljluestc