wl_display#1.error(wl_display#1, 0, "invalid object 3") - linux
I'm new to wayland, today I wrote a simple wayland server/client sample, but got some error, please help! what I expected is client draw a buffer and commit, then server got this buffer and present to screen by gl/egl.
main part of server:
wl_display_add_socket
....
template <class T>
void DestroyUserData(wl_resource* resource) {
TakeUserDataAs<T>(resource);
}
void compositor_create_surface(wl_client* client,
wl_resource* resource,
uint32_t id) {
wl_resource* surface_resource = wl_resource_create(
client, &wl_surface_interface, wl_resource_get_version(resource), id);
wl_resource_set_implementation(surface_resource, &surface_implementation, nullptr,
DestroyUserData<T>);
}
const struct wl_compositor_interface compositor_implementation = {
compositor_create_surface, compositor_create_region};
const uint32_t compositor_version = 3;
void bind_compositor(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource =
wl_resource_create(client, &wl_compositor_interface,
std::min(version, compositor_version), id);
wl_resource_set_implementation(resource, &compositor_implementation, data,
nullptr);
}
wl_global_create(wl_display_.get(), &wl_compositor_interface,
compositor_version, display_, bind_compositor);
wl_event_loop_dispatch
....
and others
and main part of client:
void Simple::Run(int frames, PresentationFeedback* feedback) {
wl_callback_listener frame_listener = {FrameCallback};
wp_presentation_feedback_listener feedback_listener = {
FeedbackSyncOutput, FeedbackPresented, FeedbackDiscarded};
Presentation presentation;
int frame_count = 0;
std::unique_ptr<wl_callback> frame_callback;
bool frame_callback_pending = false;
do {
if (frame_callback_pending)
continue;
if (frame_count == frames)
break;
Buffer* buffer = DequeueBuffer();
if (!buffer)
continue;
SkCanvas* canvas = buffer->sk_surface->getCanvas();
static const SkColor kColors[] = {SK_ColorRED, SK_ColorBLACK};
canvas->clear(kColors[++frame_count % arraysize(kColors)]);
if (gr_context_) {
gr_context_->flush();
glFinish();
}
wl_surface_set_buffer_scale(surface_.get(), scale_);
wl_surface_set_buffer_transform(surface_.get(), transform_);
wl_surface_damage(surface_.get(), 0, 0, surface_size_.width(),
surface_size_.height());
wl_surface_attach(surface_.get(), buffer->buffer.get(), 0, 0);
// Set up the frame callback.
frame_callback_pending = true;
frame_callback.reset(wl_surface_frame(surface_.get()));
wl_callback_add_listener(frame_callback.get(), &frame_listener,
&frame_callback_pending);
// Set up presentation feedback.
Frame frame;
frame.feedback.reset(
wp_presentation_feedback(globals_.presentation.get(), surface_.get()));
wp_presentation_feedback_add_listener(frame.feedback.get(),
&feedback_listener, &presentation);
frame.submit_time = base::TimeTicks::Now();
presentation.submitted_frames.push_back(std::move(frame));
wl_surface_commit(surface_.get());
wl_display_flush(display_.get());
} while (wl_display_dispatch(display_.get()) != -1);
if (feedback)
*feedback = presentation.feedback;
}
set WAYLAND-DEBUG on, then start server and client,
client report an error, and all the debug info:
[137355.232] -> wl_display#1.get_registry(new id wl_registry#2)
[137355.241] -> wl_display#1.sync(new id wl_callback#3)
[137355.527] wl_display#1.delete_id(3)
[137355.550] wl_registry#2.global(1, "wl_compositor", 3)
[137355.558] -> wl_registry#2.bind(1, "wl_compositor", 3, new id [unknown]#4)
[137355.575] wl_registry#2.global(2, "wl_shm", 1)
[137355.589] -> wl_registry#2.bind(2, "wl_shm", 1, new id [unknown]#5)
[137355.619] wl_registry#2.global(3, "zwp_linux_dmabuf_v1", 2)
[137355.624] -> wl_registry#2.bind(3, "zwp_linux_dmabuf_v1", 1, new id [unknown]#6)
[137355.628] wl_registry#2.global(4, "wl_subcompositor", 1)
[137355.633] -> wl_registry#2.bind(4, "wl_subcompositor", 1, new id [unknown]#7)
[137355.638] wl_registry#2.global(5, "wl_shell", 1)
[137355.675] -> wl_registry#2.bind(5, "wl_shell", 1, new id [unknown]#8)
[137355.697] wl_registry#2.global(6, "wl_output", 2)
[137355.702] wl_registry#2.global(7, "zcr_vsync_feedback_v1", 1)
[137355.726] wl_registry#2.global(8, "wp_presentation", 1)
[137355.732] -> wl_registry#2.bind(8, "wp_presentation", 1, new id [unknown]#9)
[137355.770] wl_registry#2.global(9, "zcr_alpha_compositing_v1", 1)
[137355.781] wl_callback#3.done(0)
[137355.943] -> wl_shm#5.create_pool(new id wl_shm_pool#3, fd 11, 262144)
[137355.983] -> wl_shm_pool#3.create_buffer(new id wl_buffer#10, 0, 256, 256, 1024, 0)
[137356.038] -> wl_shm#5.create_pool(new id wl_shm_pool#11, fd 12, 262144)
[137356.045] -> wl_shm_pool#11.create_buffer(new id wl_buffer#12, 0, 256, 256, 1024, 0)
[137356.081] -> wl_compositor#4.create_surface(new id wl_surface#13)
[137356.096] -> wl_compositor#4.create_region(new id wl_region#14)
[137356.100] -> wl_region#14.add(0, 0, 256, 256)
[137356.106] -> wl_surface#13.set_opaque_region(wl_region#14)
[137356.112] -> wl_region#14.destroy()
[137356.114] -> wl_shell#8.get_shell_surface(new id wl_shell_surface#15, wl_surface#13)
[137356.120] -> wl_shell_surface#15.set_title("Wayland Client")
[137356.125] -> wl_shell_surface#15.set_toplevel()
[137356.425] -> wl_surface#13.set_buffer_scale(1)
[137356.431] -> wl_surface#13.set_buffer_transform(0)
[137356.434] -> wl_surface#13.damage(0, 0, 256, 256)
[137356.455] -> wl_surface#13.attach(wl_buffer#10, 0, 0)
[137356.479] -> wl_surface#13.frame(new id wl_callback#16)
[137356.498] -> wp_presentation#9.feedback(wl_surface#13, new id wp_presentation_feedback#17)
[137356.518] -> wl_surface#13.commit()
[137356.768] wl_display#1.error(wl_display#1, 0, "invalid object 3")
wl_display#1: error 0: invalid object 3
[137356.871] -> wl_shm_pool#11.destroy()
[137356.902] -> wl_buffer#12.destroy()
[137356.913] -> wl_shm_pool#3.destroy()
[137356.957] -> wl_buffer#10.destroy()
[137356.965] -> wl_subcompositor#7.destroy()
[137356.967] -> zwp_linux_dmabuf_v1#6.destroy()
[137356.969] -> wp_presentation#9.destroy()
[137356.972] -> wl_surface#13.destroy()
server log:
[3513445.412] wl_display#1.get_registry(new id wl_registry#2)
[3513445.422] -> wl_registry#2.global(1, "wl_compositor", 3)
[3513445.430] -> wl_registry#2.global(2, "wl_shm", 1)
[3513445.434] -> wl_registry#2.global(3, "zwp_linux_dmabuf_v1", 2)
[3513445.439] -> wl_registry#2.global(4, "wl_subcompositor", 1)
[3513445.442] -> wl_registry#2.global(5, "wl_shell", 1)
[3513445.446] -> wl_registry#2.global(6, "wl_output", 2)
[3513445.450] -> wl_registry#2.global(7, "zcr_vsync_feedback_v1", 1)
[3513445.454] -> wl_registry#2.global(8, "wp_presentation", 1)
[3513445.457] -> wl_registry#2.global(9, "zcr_alpha_compositing_v1", 1)
[3513445.461] wl_display#1.sync(new id wl_callback#3)
[3513445.465] -> wl_callback#3.done(0)
[3513445.467] -> wl_display#1.delete_id(3
[3513446.767] wl_registry#2.bind(1, "wl_compositor", 3, new id [unknown]#4)
[3513446.786] wl_registry#2.bind(2, "wl_shm", 1, new id [unknown]#5)
[3513446.794] -> wl_shm#5.format(875709016)
[3513446.797] -> wl_shm#5.format(875708993)
[3513446.799] -> wl_shm#5.format(1)
[3513446.801] -> wl_shm#5.format(0)
[3513446.803] wl_registry#2.bind(3, "zwp_linux_dmabuf_v1", 1, new id [unknown]#6)
[3513446.808] -> zwp_linux_dmabuf_v1#6.format(909199186)
[3513446.811] -> zwp_linux_dmabuf_v1#6.format(875709016)
[3513446.813] -> zwp_linux_dmabuf_v1#6.format(875708993)
[3513446.815] -> zwp_linux_dmabuf_v1#6.format(875713112)
[3513446.817] -> zwp_linux_dmabuf_v1#6.format(875713089)
[3513446.819] -> zwp_linux_dmabuf_v1#6.format(842094158)
[3513446.821] -> zwp_linux_dmabuf_v1#6.format(842094169)
[3513446.823] wl_registry#2.bind(4, "wl_subcompositor", 1, new id [unknown]#7)
[3513446.829] wl_registry#2.bind(5, "wl_shell", 1, new id [unknown]#8)
[3513446.840] wl_registry#2.bind(8, "wp_presentation", 1, new id [unknown]#9)
[3513446.845] -> wp_presentation#9.clock_id(1)
[3513446.848] wl_shm#5.create_pool(new id wl_shm_pool#3, fd 235, 262144)
[3513446.855] -> wl_display#1.error(wl_display#1, 0, "invalid object 3")
Related
How do I run every exported function
So i have this mess of a js file cardPool = [] class Card { constructor(name = "", portrait = "", bloodCost = 0, boneCost = 0, power = 0, health = 1, sigilList = ["No sigil"]) { this.name = name this.portrait = portrait; this.bloodCost = bloodCost; this.boneCost = boneCost; this.power = power; this.health = health; this.sigilList = sigilList; cardPool.push(this) } Damage(dmg = 1) { this.health -= dmg } } blank = new Card("blank", "🔳"); income = new Card("income", "⬇️"); module.exports = { Card, blank, income, bear: function () { new Card("Grizzly", "🐻", 3, 0, 4, 6) }, wolf: function () { new Card("Wolf", "🐺", 2, 0, 3, 2) }, cardPool, }; All I want to do is on start up it run all of the function being exported. There more function that I export but here only a few so stack overflow won't scream at me. This is for a game that I'm making to be able to handle multiple instance of the same card. You can read about why I make new card using function here: How to change a local class varible node js . And I need a card pool so that I can do stuff in another file here my other question: How can i put an object inside a list on Initialization. Now I need on startup put all the card that I make in the module.export in the cardPool.
The best way to do this would be placing the functions in some kind of container (for example an array or a map) (in case you later want to export other functions from the file that don't create cards). Here's the simplest way with an array: // Note the return statements! The functions will not return anything without them! function bear () { return new Card("Grizzly", "🐻", 3, 0, 4, 6) } function wolf () { return new Card("Wolf", "🐺", 2, 0, 3, 2) } module.exports = { // ... cardCreatorFunctions: [bear, wolf, /* and maybe others */], } Then, you can iterate through the array and push created cards into cardPool one-by-one: for (let fun of cardLib.cardCreatorFunctions) { cardLib.cardPool.push(fun()) } Or you can do it in one statement: cardLib.cardPool = cardLib.cardCreatorFunctions.map(fun => fun())
spring-data-cassandra-reactive improve performance of ReactiveCrudRepository.save
I have simple showcase with ReactiveCrudRepository, which shows almost 2x difference in insertion speed using ReactiveCrudRepository.save() vs ReactiveCqlOperations.execute() Here is the code: Entity: #Table("snapshot") #Value #Builder #EqualsAndHashCode(callSuper = false) #RequiredArgsConstructor public class SnapshotRecord { #PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) long id; #PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) short market; #PrimaryKeyColumn(ordinal = 3, type = PrimaryKeyType.CLUSTERED) Instant slot; double value; } Repository: public interface SnapshotRepository extends ReactiveCrudRepository<SnapshotRecord, Long> { default Mono<Boolean> saveViaCql(ReactiveCqlOperations cqlOps, SnapshotRecord record) { return cqlOps.execute( "INSERT INTO snapshot (id, market,slot,value) VALUES (?,?,?,?) USING TIMESTAMP ?;", ps -> { return ps.bind( record.getId(), record.getMarket(), record.getSlot(), record.getValue(), record.getSlot().toEpochMilli() * 1000 ); } ); } } Runner: Flux<SnapshotRecord> data = Flux.generate(Object::new, (state, sink) -> { ThreadLocalRandom random = ThreadLocalRandom.current(); sink.next( new SnapshotRecord( random.nextLong(), (short) random.nextInt(), Clock.systemUTC().instant(), random.nextDouble() ) ); return state; }); subscription = data //.flatMap((SnapshotRecord record) -> repository.saveViaCql(cqlOps, record), 512, 2048) .flatMap(repository::save, 512, 2048) //doing this runs almost 2x slower than previous line .doOnNext(d -> success.incrementAndGet()) .onErrorContinue((throwable, object) -> fail.incrementAndGet()) .subscribe(); Full project link on Github: https://github.com/piddubnyi/spring-data-cassandra-performnace Is there any way to improve insertion performance of repository.save(), or spring-proxy is really costly in this case?
UITextChecker for Set of Strings - Swift 4.2
I currently have this Extension thanks to #Leo Dabus. It works perfectly for a single String, but how would I implement this same logic to an Set of Strings like var mySet = ["word", "notaword", "stillnotaword"]. In this example, I would want the function to only identify the first index as true (i.e. an English word). extension String { public mutating func isEnglishWord() -> Bool { return UITextChecker().rangeOfMisspelledWord(in: self, range: NSRange(location: 0, length: utf16.count), startingAt: 0, wrap: false, language: "en_US").location == NSNotFound } } var myString = "word" myString.isEnglishWord()
let words = ["word", "notaword", "stillnotaword"] let validWords = words.filter { word -> Bool in return word.isEnglishWord() } let wordsArray : NSArray = NSArray(array: words) let validWordsIndexes = wordsArray.indexesOfObjects { (word, index, _) -> Bool in return (word as! String).isEnglishWord() } print(validWords) print(validWordsIndexes) extension String { public func isEnglishWord() -> Bool { return UITextChecker().rangeOfMisspelledWord(in: self, range: NSRange(location: 0, length: utf16.count), startingAt: 0, wrap: false, language: "en_US").location == NSNotFound } } I have added the code to print valid words and indexes of valid words. You can choose which ever suits you. Thanks
Java 8 CompletedFuture web crawler doesn't crawl past one URL
I'm playing with the newly introduced concurrency features in Java 8, working exercises from the book "Java SE 8 for the Really Impatient" by Cay S. Horstmann. I created the following web crawler using the new CompletedFuture and jsoup. The basic idea is given a URL, it'll find first m URLs on that page and repeat the process n times. m and n are parameters, of course. Problem is the program fetches the URLs for the initial page but doesn't recurse. What am I missing? static class WebCrawler { CompletableFuture<Void> crawl(final String startingUrl, final int depth, final int breadth) { if (depth <= 0) { return completedFuture(startingUrl, depth); } final CompletableFuture<Void> allDoneFuture = allOf((CompletableFuture[]) of( startingUrl) .map(url -> supplyAsync(getContent(url))) .map(docFuture -> docFuture.thenApply(getURLs(breadth))) .map(urlsFuture -> urlsFuture.thenApply(doForEach( depth, breadth))) .toArray(size -> new CompletableFuture[size])); allDoneFuture.join(); return allDoneFuture; } private CompletableFuture<Void> completedFuture( final String startingUrl, final int depth) { LOGGER.info("Link: {}, depth: {}.", startingUrl, depth); CompletableFuture<Void> future = new CompletableFuture<>(); future.complete(null); return future; } private Supplier<Document> getContent(final String url) { return () -> { try { return connect(url).get(); } catch (IOException e) { throw new UncheckedIOException( " Something went wrong trying to fetch the contents of the URL: " + url, e); } }; } private Function<Document, Set<String>> getURLs(final int limit) { return doc -> { LOGGER.info("Getting URLs for document: {}.", doc.baseUri()); return doc.select("a[href]").stream() .map(link -> link.attr("abs:href")).limit(limit) .peek(LOGGER::info).collect(toSet()); }; } private Function<Set<String>, Stream<CompletableFuture<Void>>> doForEach( final int depth, final int breadth) { return urls -> urls.stream().map( url -> crawl(url, depth - 1, breadth)); } } Test case: #Test public void testCrawl() { new WebCrawler().crawl( "http://en.wikipedia.org/wiki/Java_%28programming_language%29", 2, 10); }
The problem is in the following code: final CompletableFuture<Void> allDoneFuture = allOf( (CompletableFuture[]) of(startingUrl) .map(url -> supplyAsync(getContent(url))) .map(docFuture -> docFuture.thenApply(getURLs(breadth))) .map(urlsFuture -> urlsFuture.thenApply(doForEach(depth, breadth))) .toArray(size -> new CompletableFuture[size])); For some reason you are doing all this inside a stream of one element (is that a part of the exercise?). The result is that allDoneFuture is not tracking the completion of the sub-tasks. It's tracking the completion of the Stream<CompletableFuture> that comes from doForEach. But that stream is ready right away and the futures inside of it are never asked to complete. Fix it by removing the stream that doesn't do anything helpful: final CompletableFuture<Void> allDoneFuture=supplyAsync(getContent(startingUrl)) .thenApply(getURLs(breadth)) .thenApply(doForEach(depth,breadth)) .thenApply(futures -> futures.toArray(CompletableFuture[]::new)) .thenCompose(CompletableFuture::allOf);
How to implement Haskell's splitEvery in Swift?
PROBLEM let x = (0..<10).splitEvery( 3 ) XCTAssertEqual( x, [(0...2),(3...5),(6...8),(9)], "implementation broken" ) COMMENTS I am running into problems calculating number of elements in the Range, etc... extension Range { func splitEvery( nInEach: Int ) -> [Range] { let n = self.endIndex - self.startIndex // ERROR - cannot invoke '-' with an argument list of type (T,T) } }
The values in a range are of ForwardIndexType, so you can only advance() them, or compute the distance(), but the subtraction - is not defined. The advance amount has to be of the corresponding type T.Distance. So this would be a possible implementation: extension Range { func splitEvery(nInEach: T.Distance) -> [Range] { var result = [Range]() // Start with empty array var from = self.startIndex while from != self.endIndex { // Advance position, but not beyond the end index: let to = advance(from, nInEach, self.endIndex) result.append(from ..< to) // Continue with next interval: from = to } return result } } Example: println( (0 ..< 10).splitEvery(3) ) // Output: [0..<3, 3..<6, 6..<9, 9..<10] Note however that 0 ..< 10 is not a list (or array) of integers. To split an array into subarrays you could define a similar extension: extension Array { func splitEvery(nInEach: Int) -> [[T]] { var result = [[T]]() for from in stride(from: 0, to: self.count, by: nInEach) { let to = advance(from, nInEach, self.count) result.append(Array(self[from ..< to])) } return result } } Example: println( [1, 1, 2, 3, 5, 8, 13].splitEvery(3) ) // Output: [[1, 1, 2], [3, 5, 8], [13]] A more general approach could be to split all sliceable objects. But Sliceable is protocol and protocols cannot be extended. What you can do instead is to define a function that takes the sliceable object as the first argument: func splitEvery<S : Sliceable>(seq : S, nInEach : S.Index.Distance) -> [S.SubSlice] { var result : [S.SubSlice] = [] var from = seq.startIndex while from != seq.endIndex { let to = advance(from, nInEach, seq.endIndex) result.append(seq[from ..< to]) from = to } return result } (Note that this function is completely unrelated to the (extension) methods defined above.) Example: println( splitEvery("abcdefg", 2) ) // Output: [ab, cd, ef, g] println( splitEvery([3.1, 4.1, 5.9, 2.6, 5.3], 2) ) // Output: [[3.1, 4.1], [5.9, 2.6], [5.3]] Ranges are not sliceable, but you could define a separate function that takes a range argument: func splitEvery<T>(range : Range<T>, nInEach : T.Distance) -> [Range<T>] { var result : [Range<T>] = [] var from = range.startIndex while from != range.endIndex { let to = advance(from, nInEach, range.endIndex) result.append(from ..< to) from = to } return result } Example: println( splitEvery(0 ..< 10, 3) ) // Output: [0..<3, 3..<6, 6..<9, 9..<10]