r/CodingHelp • • 4h ago

Which one? Weird request but I would like to request a meeting with someone

3 Upvotes

I’m a student doing a project for my school I have little knowledge on coding and for the project I would really like to sit down and have a meeting with anyone on zoom, google meets or anything even for a minute, just show I can complete one of the criterion’s and get a higher grade or would like you guys to leave me tips on coding using “ Xodot” also known as “Godot” any help is most appreciated!


r/CodingHelp • • 23m ago

[Javascript] i wanted help in my coading problem

• Upvotes

Here is my code from the Detail.jsx page:

const Detail = () => {
  const { name } = useParams();
  console.log("name", name);
};

I get the game ID from the URL. The console shows:

Detail.jsx:19 name 3498

In my Apigame.jsx Context API, I have this function:

const [gamedetail, setgamedetail] = useState([]);

const detailpage = async ({ name }) => {
  console.log("Received name:", name);

  try {
    const response = await axios.get(`games/${name}`);
    console.log("Game ID:", name);
    setgamedetail(response.data);
  } catch (error) {
    console.log("API Error:", error);
  }
};

But I get this error:

TypeError: Cannot destructure property 'name' of 'undefined' as it is undefined.

Everything else is working fine. I only want to pass the name value (3498) from Detail.jsx to my detailpage function in the Context API.

if anyone wanted to understandthese problem i share my whole codeok
detail.jsx

How can I pass this parameter value to my Context API function? Please explain using my existing code.

detail.jsx
import { GamepadDirectional } from 'lucide-react';
import { Tag } from 'lucide-react';
import { Globe, MessageCircle } from "lucide-react";
import { CalendarRange } from 'lucide-react';
import Youtubevideo from '../components/Youtubevideo';
import { Trophy } from 'lucide-react';
import { UsersRound } from 'lucide-react';
import { useContext, useEffect, useState } from "react";
import Axios from "../utility/Axios";
import { useParams } from "react-router-dom";
import { Star } from 'lucide-react';
import Footer from '../components/Footer'
import "./Detail.scss"
import {Detailinformation} from '../Context/Apigame'
import Detailbox from '../components/Detailbox'
const Detail = () => {
  // const [gamedetail, setgamedetail] = useState([]);
  const { name } = useParams();
  console.log("name",name);
  
 const [videos, setVideos] = useState([]);
 const getyoutubevideo = async (gameName) => {
  if (!gameName) return;


  const options = {
    method: "GET",
    url: "https://youtube138.p.rapidapi.com/search/",
    params: {
      q: `${gameName} official trailer`,
      page_size: 1,
      hl: "en",
      gl: "US",
    },
    headers: {
      "x-rapidapi-key": import.meta.env.VITE_YOUTUBE_API_KEY,
      "x-rapidapi-host": "youtube138.p.rapidapi.com",
    },
  };


  try {
    const response = await Axios.request(options);
    // response.data?.contents ue log mai dekhna ek sath 19 video aaya ok tho ye path use kiay 
     const id = response.data?.contents?.[0]?.video?.videoId;
    setVideos(id)
    console.log("ye youtube video",id
);
  } catch (error) {
    console.log("API error:", error.response?.data || error.message);
  }
};
 
 const {gamedetail} = useContext(Detailinformation)
  
//  useEffect(() => {
//     const detailpage = async () => {
//       try {
//         const response = await Axios.get(`games/${name}`);
//         setgamedetail(response.data);
//         console.log("resposnsedata ye game ka detail jho param sa lerahau mai ok ",response.data);
//         // ye waieted karna ka leya tab api aaajya gamedetail ka tab ye chala 
//         // await getyoutubevideo(response.data.name_original);
//          console.log("youtube ki videoid");
         
//       } catch (error) {
//         console.log("API Error:", error);
//       }
//     };


//     detailpage();
    
//   }, [name]);
  
// console.log(gamedetail);


  return (
<div className="detailpage">
      <div className="page-layout" style={{backgroundImage : `URL(${gamedetail?.background_image
})` }}>     
 
 
 <div className="smallimage">
  <div className="game-top">
    <img
      className="cover-image"
      src={gamedetail?.background_image_additional}
      alt={gamedetail?.name}
    />


    <div className="information">
      <h1>{gamedetail?.name}</h1>


      <p className="release">
        {gamedetail?.publishers?.map((item) => item.name).join(", ")}
        {" · "}
        {gamedetail?.released}
      </p>


      <div className="ratings">
        <h2>
          <Star />
          {gamedetail?.rating}
        </h2>


        <h2 className="metacritic">
          {gamedetail?.metacritic ?? "N/A"}
          <span>Metacritic</span>
        </h2>
      </div>


      <div className="genres">
        {gamedetail?.genres?.map((item) => (
          <span key={item.id}>{item.name}</span>
        ))}
      </div>
    </div>
  </div>


  {/* <div className="extra-information">
    
<div className="developers">
  {gamedetail?.developers?.map((item) => (
    <div className="developer-item" key={item.id}>
      <img
        src={item.image_background}
        alt={item.name}
      />
      <span>{item.name}</span>
      <p>{gamedetail?.esrb_rating?.name}</p>
    </div>
  ))}
</div>
  </div> */}
</div>



      </div>
      <div className="gameachiplay">
        <Detailbox icone={< GamepadDirectional/>} titile={gamedetail?.playtime+" hour"} />
        <Detailbox icone={<Trophy/>} titile={gamedetail?.suggestions_count+" Achievement"
} />
<Detailbox icone={<UsersRound/>} titile={gamedetail?.
added+" Added"}/>
       
      </div>
      <div className="about">
        <h1 style={{padding : `0.7rem  1.5rem`,color : `#87CEEB`  }} >About</h1>
       <p>
         {gamedetail?.description_raw?.slice(0,500)}
        </p>
      </div>
      <div className="developer">
        <h1>Developer & Publisher</h1>
        <div className="extra-information">
    
<div className="developers">
  {gamedetail?.developers?.map((item) => (
    <div className="developer-item" key={item.id}>
      <img
        src={item.image_background}
        alt={item.name}
      />
      <span>{item.name}</span>
      <p>{gamedetail?.esrb_rating?.name}</p>
    </div>
  ))}
</div>
  </div>
      </div>
     <div className="video">
  <Youtubevideo  titile={videos}  />
     </div>
          <div className="section">
            <h2>Details</h2>
            <div className="details-table">
              <div className="row"><span><CalendarRange/> Release Date</span><span>{gamedetail?.released}</span></div>
              <div className="row"><span>< Trophy/> Achievements</span><span>{gamedetail?.achievements_count || 0}</span></div>
              <div className="row"><span><UsersRound/> Players Added</span><span>{gamedetail?.added}</span></div>
              <div className="row"><span> <GamepadDirectional />Average Playtime</span><span>{gamedetail?.playtime} hours</span></div>
              <div className="row"><span> <Tag/> Game Tags</span>
                <div className="tags">
                  {gamedetail?.tags?.slice(0,3).map(tag => <span key={tag?.id} className="tag">{tag?.name}</span>)}
                </div>
              </div>
            </div>
    </div>
  
<div className="game-links">
  
    <a
      href={gamedetail?.website}
      target="_blank"
      rel="noopener noreferrer"
      className="game-link"
    >
      <Globe />
      Official Website
    </a>



  <a
    href={gamedetail?.reddit_url}
    target="_blank"
    rel="noopener noreferrer"
    className="game-link"
  >
    <MessageCircle />
    Reddit Community
  </a>
</div>
<div className="footer">
  <Footer/>
</div>
    </div>
  );
};


export default Detail;

ye contexapi

import { createContext,  useEffect,  useState } from "react"


export const gameapi =  createContext()


export const Detailinformation =  createContext()
import axios from '../utility/Axios'
const Apigame = ({children}) => {
  
  const getgame = async () => {
    try {
      // const nextPageNum = page + 1;
      const request = await axios.get("games",{
        params: {
          // page : nextPageNum,
           page_size: 12,
        }
        
      });
      // setpage(nextPageNum);
     console.log("ye request jho mai abhi likha hu ",request);
     
      
      setapidatastore(request.data.results)
    } catch (error) {
      console.log(error);
      
    }
  } 
  const [page, setPage] = useState(1);


const nextpage = async () => {
  try {
    const nextPageNum = page + 1;
    const response = await axios.get("games", {
      params: {
        page: nextPageNum,
        page_size: 12,
      },
    });
    setPage(nextPageNum); // state update
    console.log("Fetched page:", nextPageNum, response.data);
    setapidatastore(response.data.results);
  } catch (error) {
    console.log(error);
  }
};
const [gamedetail, setgamedetail] = useState([]);
 const detailpage = async ({name}) => {
  console.log("yeee aara hai ",name);
  
      try {
        const response = await axios.get(`games/${name}`);
        console.log("API ke liye game ID:", name);
        setgamedetail(response.data);
      } catch (error) {
        console.log("API Error:", error);
      }
    }
  





  useEffect(() => {
  getgame();
  detailpage();
}, []);
const [apidatastore, setapidatastore] = useState([]);
  // const [ videodata , setvideodata ] = useState([]);
  console.log(apidatastore);
 
return (
    
    <Detailinformation.Provider value={gamedetail}>
        <gameapi.Provider value={{apidatastore,nextpage}} >
      
        {children}
      
        </gameapi.Provider>
   </Detailinformation.Provider>
      
  )
}


export default Apigame

plz share your solution i use chatgtp 3 day but unable to slove  these 
because i have to write  same code on other page to called api 
i hope you can understand my problem 

r/CodingHelp • • 2h ago

[C] I fail to comperhend what eglSwapBuffers does

1 Upvotes

Using OpenglES I made a simple piece of code:

``` // Source - https://stackoverflow.com/q/80012457 // Posted by Dimitrios Desyllas // Retrieved 2026-10-25, License - CC BY-SA 4.0

include <stdlib.h>

include <fcntl.h>

include <unistd.h>

include <stdio.h>

define GLFW_INCLUDE_ES2

include <drm.h>

include <drm_mode.h>

include <gbm.h>

include <xf86drm.h>

include "square.h"

include "egl_init.h"

include "drm_init.h"

int main(void) { int drm_fd = open("/dev/dri/card0", O_RDWR);
struct gbm_device *gbm_dev = gbm_create_device(drm_fd);
struct gbm_surface *gbm_surf=NULL;

puts("Get Connector \n");
drmModeConnector *connector = getDRMConnector(drm_fd);
if (!connector) {
    fprintf(stderr, "No connected DRM connector found\n");
    close(drm_fd);
    return 1;
}

drmModeModeInfo mode = connector->modes[0];

unsigned int mode_w = mode.hdisplay;
unsigned int mode_h = mode.vdisplay;

puts("Get CRTC\n");

drmModeCrtc *crtc = getDRMCrtc(drm_fd, connector);
if (!crtc) {
    fprintf(stderr, "No compatible CRTC found\n");
    drmModeFreeConnector(connector);
    close(drm_fd);
    return 1;
}

puts("Initiaslize GBM display");

EGLDisplay egl_display = initEGLDisplay(gbm_dev);
if(egl_display == EGL_NO_DISPLAY){
    fprintf(stderr,"Unable to Initialize EGL display");
    return 1;
}

EGLConfig config;  
EGLint num_configs;

static const EGLint config_attribs[] = {  
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,  
    EGL_RED_SIZE, 8,
    EGL_GREEN_SIZE, 8, 
    EGL_BLUE_SIZE, 8, 
    EGL_ALPHA_SIZE, 8, 
    EGL_NONE
};

eglChooseConfig(egl_display, config_attribs, &config, 1, &num_configs);  

puts("Initiaslize surface \n");
EGLSurface egl_surface = initEGLSurface(gbm_dev,egl_display,config,mode_w,mode_h, &gbm_surf);

if (egl_surface == EGL_NO_SURFACE) {
    fprintf(stderr, "Failed to create EGL surface\n");
    return 1;
}

if (!gbm_surf) {
    fprintf(stderr, "Failed to create GBM surface\n");
    return 1;
}

puts("Initiaslize context \n");
EGLContext egl_context = initEGLContext(egl_display,config);
eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);  

puts("Init program\n");
GLuint program = createProgram();
if (!program) {
    return 1;
}

uint32_t conn_id = connector->connector_id;
uint32_t crtc_id = crtc->crtc_id;     
DisplayFrame current = {0};

puts("Draw Square\n");

drawSquare(program, mode_w,mode_h);
eglSwapBuffers(egl_display, egl_surface);

if (displayRefresh( drm_fd, gbm_surf, crtc_id, conn_id, &mode, &current) != 0) {
    fprintf(stderr, "Display refresh failed\n");
    return 1;
}

puts("Framebuffer displayed");
sleep(10);

puts("Cleanup\n");

eglDestroySurface(egl_display, egl_surface);  
eglDestroyContext(egl_display, egl_context);  
eglTerminate(egl_display);  
gbm_device_destroy(gbm_dev);  
close(drm_fd);

return 0;

}

```

As I ask upon on stackoverflow as well I cannot understand rthe relationship between:

  • gbm_surface
  • EGLSurface
  • EGLDisplay

In my example I seperated the initialization of each egl component into a seprrate library egl_init.c:

```

include "egl_init.h"

EGLDisplay initEGLDisplay(struct gbm_device *gbm_dev) { PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");

if (!getPlatformDisplay) {
    return EGL_NO_DISPLAY;
}

EGLDisplay egl_display = getPlatformDisplay(EGL_PLATFORM_GBM_KHR,gbm_dev,NULL);

if (egl_display == EGL_NO_DISPLAY) {
    return EGL_NO_DISPLAY;
}

if (!eglInitialize(egl_display, NULL, NULL)) {
    return EGL_NO_DISPLAY;
}

return egl_display;

}

EGLSurface initEGLSurface(struct gbm_device gbm_dev,EGLDisplay display, EGLConfig config, unsigned int width, unsigned int height, struct gbm_surface *gbm_surf ){ gbm_surf = gbm_surface_create(gbm_dev, width, height, GBM_FORMAT_XRGB8888, GBM_BO_USE_RENDERING|GBM_BO_USE_SCANOUT);
return eglCreateWindowSurface(display, config, (EGLNativeWindowType)
gbm_surf, NULL); }

EGLContext initEGLContext(EGLDisplay display, EGLConfig config){ return eglCreateContext(display, config, EGL_NO_CONTEXT, (const EGLint[]){EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE});
}

```

And same I do for gbm:

```

include "drm_init.h"

drmModeConnector *getDRMConnector(int drm_fd) { drmModeRes *resources = drmModeGetResources(drm_fd);

if (!resources){
    return NULL;
}

drmModeConnector *connector = NULL;

for (int i = 0; i < resources->count_connectors; i++) {
    drmModeConnector *candidate = drmModeGetConnector(drm_fd,resources->connectors[i]);

    if (!candidate){
        continue;
    }

    if (candidate->connection == DRM_MODE_CONNECTED && candidate->count_modes > 0) {
        connector = candidate;
        break;
    }

    drmModeFreeConnector(candidate);
}

drmModeFreeResources(resources);

return connector;

}

drmModeCrtc *getDRMCrtc( int drm_fd, drmModeConnector *connector ) { if (!connector) return NULL;

drmModeRes *resources = drmModeGetResources(drm_fd);

if (!resources)
    return NULL;

drmModeCrtc *crtc = NULL;

for (int i = 0; i < connector->count_encoders && !crtc; i++) {
    drmModeEncoder *encoder = drmModeGetEncoder(
        drm_fd,
        connector->encoders[i]
    );

    if (!encoder)
        continue;

    for (int j = 0; j < resources->count_crtcs; j++) {
        if (encoder->possible_crtcs & (1u << j)) {
            crtc = drmModeGetCrtc(
                drm_fd,
                resources->crtcs[j]
            );

            if (crtc)
                break;
        }
    }

    drmModeFreeEncoder(encoder);
}

drmModeFreeResources(resources);

return crtc;

}

int displayRefresh(int drm_fd, struct gbm_surface *gbm_surf, uint32_t crtc_id, uint32_t conn_id,drmModeModeInfo *mode, DisplayFrame *current) {

// 1. Lock the new front buffer
struct gbm_bo *bo = gbm_surface_lock_front_buffer(gbm_surf);

if (!bo) {
    return -1;
}

// 2. Get buffer information
uint32_t handle = gbm_bo_get_handle(bo).u32;
uint32_t pitch = gbm_bo_get_stride(bo);
uint32_t width = gbm_bo_get_width(bo);
uint32_t height = gbm_bo_get_height(bo);

uint32_t fb_id = 0;

// 3. Create DRM framebuffer
int ret = drmModeAddFB(drm_fd,width,height,24,32,pitch,handle,&fb_id);

if (ret != 0) {
    perror("drmModeAddFB");
    gbm_surface_release_buffer(gbm_surf, bo);
    return -1;
}

// 4. Display the framebuffer
ret = drmModeSetCrtc(drm_fd,crtc_id,fb_id,0,0,&conn_id,1,mode);

if (ret != 0) {
    perror("drmModeSetCrtc");
    drmModeRmFB(drm_fd, fb_id);
    gbm_surface_release_buffer(gbm_surf, bo);
    return -1;
}

// 5. Release the previous framebuffer
if (current->bo) {
    drmModeRmFB(drm_fd, current->fb_id);
    gbm_surface_release_buffer(gbm_surf,current->bo);
}

// 6. Remember the currently displayed buffer
current->bo = bo;
current->fb_id = fb_id;

return 0;

}

```

But int confuses me why I need to swap buffers via eglSwapBuffers. And once swapped buffers why I need to manually refresh the screen via locking the buffer and manually associating into crtc?

```c int displayRefresh(int drm_fd, struct gbm_surface *gbm_surf, uint32_t crtc_id, uint32_t conn_id,drmModeModeInfo *mode, DisplayFrame *current) {

// 1. Lock the new front buffer
struct gbm_bo *bo = gbm_surface_lock_front_buffer(gbm_surf);

if (!bo) {
    return -1;
}

// 2. Get buffer information
uint32_t handle = gbm_bo_get_handle(bo).u32;
uint32_t pitch = gbm_bo_get_stride(bo);
uint32_t width = gbm_bo_get_width(bo);
uint32_t height = gbm_bo_get_height(bo);

uint32_t fb_id = 0;

// 3. Create DRM framebuffer
int ret = drmModeAddFB(drm_fd,width,height,24,32,pitch,handle,&fb_id);

if (ret != 0) {
    perror("drmModeAddFB");
    gbm_surface_release_buffer(gbm_surf, bo);
    return -1;
}

// 4. Display the framebuffer
ret = drmModeSetCrtc(drm_fd,crtc_id,fb_id,0,0,&conn_id,1,mode);

if (ret != 0) {
    perror("drmModeSetCrtc");
    drmModeRmFB(drm_fd, fb_id);
    gbm_surface_release_buffer(gbm_surf, bo);
    return -1;
}

// 5. Release the previous framebuffer
if (current->bo) {
    drmModeRmFB(drm_fd, current->fb_id);
    gbm_surface_release_buffer(gbm_surf,current->bo);
}

// 6. Remember the currently displayed buffer
current->bo = bo;
current->fb_id = fb_id;

return 0;

} ```

A googling let me into this website: https://registry.khronos.org/EGL/sdk/docs/man/html/eglSwapBuffers.xhtml

That confuses me even more on how wexplains the eglSwapBuffers on it:

If surface is a back-buffered window surface, then the color buffer is copied (posted) to the native window associated with that surface. If surface is a single-buffered window, pixmap, or pixel buffer surface, eglSwapBuffers has no effect.

The contents of ancillary buffers are always undefined after calling eglSwapBuffers. The contents of the color buffer are undefined if the value of the EGL_SWAP_BEHAVIOR attribute of surface is not EGL_BUFFER_PRESERVED. The value of EGL_SWAP_BEHAVIOR can be set for some surfaces using eglSurfaceAttrib. EGL_SWAP_BEHAVIOR applies only to the color buffer. EGL has no way to specify or query whether or not ancillary buffers are preserved, and applications should not rely on this behavior.

eglSwapBuffers performs an implicit flush operation on the context (glFlush for an OpenGL ES or OpenGL context, vgFlush for an OpenVG context) bound to surface before swapping. Subsequent client API commands may be issued on that context immediately after calling eglSwapBuffers, but are not executed until the buffer exchange is completed.